1 / 13

What is Node JS ?

In this tutorial, we will learn about Express.js, Install Express via the Node Package Manager and Create Sample Web server using express.js.

balajihope
Download Presentation

What is Node JS ?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ndjidoardo.bar@hypercube-research.com

  2. JS become a ECMA (European Computer Manufacturers Association) standard by 1997. It remains a standard in client- side app overyears.  JavaScript created in 1995 by BrendanEich (@Netscape labs).  Google V8, chrome, Sep2008  Node createdin2009 by Ryan Dahl using V8 power (c++& javascript) : With Node JS start being as a server-sidelanguage.

  3. Highly scalable web servers for webapplications. Web services (RESTfulAPI) Real-Time apps as its supportsWeb-Sockets. App with queuedinputs. Data streamingapps.

  4.  Single-threaded execution with the use of callback functions => not resource- intensive • suitable for high latency I/O operations e.g: databaseaccess • Scalable as it combines Server and application logic in one singleplace

  5.  Node is event-driven, it handles all requests asynchronously from on single thread.  Aevent loop is used to schedule tasks in the event-drivenprogramming.  Node programmingstyle is christened Continous-Passing Style (CPS): Every asynchronous function has at least a Callback function as one of its parameters. This later is call after the asynchronous section isexecuted. var fs =require("fs"); fs.readFile ("foo.txt", "utf8", function(error, data){ if (error){ throwerror; } console.log(data); }); console.log("Reading file...");

  6.  Using asyncmodule  Using process.nextTick()trick: functionadd(x,y,callback){ setTimeout(function() { callback(x +y); },0); } add(2, 3, console.log); console.log("The sum is:"); function add (x,y,callback) { process.nextTick(function() { callback(x +y); }); } add(2, 3, console.log); console.log("The sum is:");

  7.  Non-blocking has always to do with I/O (filesystem, database,…)  The following code is asyn but notNon-blocking: function add (x,y,callback) { process.nextTick(function(){ while (1){ callback(x +y); } }); } add(2, 3, console.log); console.log("The sum is:");

  8.  Install NodeJS: http://nodejs.org/download/

  9.  Create a app.js file with the followingcode: •  Start your server by issuing the followingcmd: • > nodeapp.js Nb: NodeJS has got aREPL!

  10.  NodeJS extensions are known asmodules •  NodeJS is being backed by an active community whichprovides • an overwhelming number ofmodules •  NPM command is used to install and manage newmodules: • Ex: • npm installasync • npm installasync@1.0.x • npm install –gasync • npm serach<MODULE_NAME> • npmoutdated • npm update npm–g • npm rmasyn •  « require(<MODULE_NAME>)» is used to load a givenmodule

  11.  ExpressJS helps to fit web projects to MCV designpattern •  To installExpressJS: • > npminstall –g express •  Express has got a scafolding capability that help you create asustainable • project structure, easy to extend andmaintain.Express-generator isthe module dedicated to thatjob. • > npminstall –g express-generator

  12.  Find a ExpressJS app example on myGITHUB: • https://github.com/ndjido/NodeJS_intro

More Related