Posted by Abhimanyu Singh | Last Updated: 18-Jan-17
It uses event-driven , non-blocking I/O model that makes it lightweight and efficient.
The execution model of Node.Js is single threaded . Now you will be wondering unlike Apache which spawn one thread for each request , how Node.Js will be handling the request . If user A has requested some database call which will take 20s and then User B have made some request then it means User B have to wait for 20s as Node.js is single threaded . I will yes if Apache will be single threaded but not in Node.Js because of event loop .
If a user is loading a page in Node.Js which has two database calls say “x” and “y” in sequence . “x” will take 20s and “y” 1s . Since database call of both “x” and “y” will be made in event loop . That is when data is fetched from database it is delivered . So for executing call “y” it will not wait for call “x” to complete though call “x” is made before call “y” . It made call “y” and deliver the data and when data for call “x” is fetched it is delivered .
In apache it will took 20+1 sec to complete but in Node.Js it will be 20s . In Apache call “x” and “y” are synchronous but in Node.Js it is asynchronous .
Use the following command to install the prerequisite
$sudo apt-get install g++ curl libssl-dev apache2-utils git-core $sudo apt-get install python-software-properties
add repository using following command
$sudo add-apt-repository ppa:chris-lea/node.js
Run the update command and install node.js
$sudo apt-get update $sudo apt-get install nodejs
NPM is Node Package Manager and used for managing dependencies for an application .
git clone http://github.com/isaacs/npm.git cd npm sudo make install
Express is web application framework for Node . It provides an MVC framework for creating Node.js web applications
$sudo npm install -g express
-g option is used so that “express” will be available to use from anywhere in the system
It is the module which provides MongoDb database support for Node.js application . It is used for MongoDB object modelling for Node.js
$sudo npm install -g mongoose
Check you installation
you will get installed package express , mongoose and node details for above command