Setup Node.js , Express Web Framework and Mongoose on Ubuntu

Posted By : Abhimanyu Singh | 14-Aug-2013

NOdeJS Mongoose Ubuntu

Node.Js is javascript based web application development platform which is used to write both client side and server side code. Now programmer can use same language on both client and server side .

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 .

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 .

Installation

  • 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
    
  • Node.js installation

    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 installation

    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 Installation

    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

  • Mongoose Installation

    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

    		$npm ls
    

    you will get installed package express , mongoose and node details for above command

Thanks

Abhimanyu

About Author

Author Image
Abhimanyu Singh

Abhimanyu is an seasoned technologist . He always keeps himself ahead in embracing and adapting new technologies/frameworks to solve business problems. He specialise in Blockchain technology , Video Content Management & enterprise software .

Request for Proposal

Name is required

Comment is required

Sending message..