Skip to content

chuksys/rest-api-node-express-mongoose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Boilerplate for getting started with REST-API development projects using Node, Express & MongoDB.

ToDo

  • Install Express and Setup App
  • Setup Item Routes
  • Setup DB and Item Model
  • Add Data Validation
  • Add Automated Tests (Mocha, Chai, Chai-http)
  • Add Authentication and API Authorization using JWT
  • Add handlers to take care of business logic currently in routes

Feel free to fork/clone.

Technologies Used

  1. Database: MongoDB
  2. ODM: Mongoose
  3. Runtime: NODE
  4. Framework: Express
  5. Testing: Mocha, Chai, Chai-http

Instructions

  1. Clone this repo into your local working dir
  2. Install all dependencies. Run
npm install
  1. Create a config folder in your root directory and a file under config named keys.js. Inside keys.js, export an object with two keys "mongoDevURI" and "mongoTestURI"; values should be the endpoint to your mongoDB instances (for both development and testing), either on MongoDB Atlas or locally". For example
module.exports = {
    mongoDevURI: encodeURI('mongodb+srv://username:password@*******************')
}

Note that this is only for development purposes. In production, this value should be an environment variable.

  1. Run
npm start

At this point, the API endpoints should work. Simply use postman to test these endpoints.

@route GET api/items
@desc GET items

http://localhost:{port_number}/api/items

@route POST api/items
@desc Add new item. Pass new item name in request body

http://localhost:{port_number}/api/items

@route PUT api/items/:id
@desc Update existing item. Pass ID of item to update as a request parameter

http://localhost:{port_number}/api/items/{item_id}

@route DELETE api/items/:id
@desc Delete existing item. Pass ID of item to delete as a request parameter

http://localhost:{port_number}/api/items/{item_id}

  1. To run the automated tests, Run
npm test

About

Boilerplate for creating REST APIs using Node, Express & Mongoose

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published