RESTful application using nodejs, expressjs and mongodb
The objective of the project is to create a basic structure for a RESTful application using nodejs, expressjs and mongodb.
Download and install nodejs (https://nodejs.org/en/)
Download and install mongodb (https://www.mongodb.org/downloads#production)
Windows
Git Bash
Postman chrome pulgin
Logger based on Winston
Environment based configuration using config(https://www.npmjs.com/package/config#introduction)
- Clone the project
- Install node modules
- Start mongodb
- Start nodejs server
- Send a POST request (Postman plugin)
- Send a GET request (Postman plugin)
- Config
- Check the log
Open Git Bash
$ cd <basepath>
$ git clone https://github.com/guptam2/node-express-mongodb-seed-project.git
$ cd <basepath>/node-express-mongodb-seed-project
$ npm install
Open Git Bash
$ cd "/c/Program Files/MongoDB/Server/3.2/bin"
$ mongod
* Mongodb folder might be different based on your installation.
$ cd <basepath>/node-express-mongodb-seed-project
$ node server.js
URL : http://localhost:3000/contacts
Request Body :
{"firstName":"m", "lastName":"g","phone":"123456789", "addressLine1":"3 test road","addressLine2":"test city", "county":"berkshire","postcode":"tt1 2tt"}
Content Type : application/jsonURL : http://localhost:3000/contacts
Different config file can be loaded by setting the NODE_ENV environment variable. Default config file is <basepath>\node-express-seed-project\config\default.json
e.g. $ export NODE_ENV=dev
It will load the <basepath>\node-express-seed-project\config\dev.json
Default log file is C:\tmp\node-express-seed-project.log
To change the log file location modify the <basepath>\node-express-seed-project\config\default.json.