Monday, June 2, 2014

Connect MongoDB with nodeJS


In following example will explain the how to make connection nodeJS with mongodb.
  • create directory connectdb
  • first create package.json file inside the connectdb directory and add following content. then cd to connectdb directory and install dependancy by using npm install command
  • In this file contains dependency modules. 
  • cd to connectdb directory and enter following command then dependency modules will be installed 
       npm install 
  • Then create server.js/ app.js file.To run nodejs application run this server.js file. This is the entry point for the application.

Create car module
Create routes/cars.js file. This contains car related code.
  You can get code from following link
 https://github.com/cchathura/cmeanstack.git/branches/connectdb