Need help with rest-api-nodejs-mongodb?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

860 Stars 309 Forks MIT License 42 Commits 21 Opened issues


A boilerplate for REST API Development with Node.js, Express, and MongoDB

Services available


Need anything else?

Contributors list

# 34,757
32 commits
# 37,080
1 commit

Nodejs Expressjs MongoDB Ready-to-use API Project Structure

Author GitHub license GitHub repo size Codacy Badge Codacy Badge Travis (.com)

A ready-to-use boilerplate for REST API Development with Node.js, Express, and MongoDB

Getting started

This is a basic API skeleton written in JavaScript ES2015. Very useful to building a RESTful web APIs for your front-end platforms like Android, iOS or JavaScript frameworks (Angular, Reactjs, etc).

This project will run on NodeJs using MongoDB as database. I had tried to maintain the code structure easy as any beginner can also adopt the flow and start building an API. Project is open for suggestions, Bug reports and pull requests.

Advertise for Job/Work Contract

I am open for a good job or work contract. You can contact me directly on my email ([email protected]) or you can download my CV from my personal website.

Buy me a Coffee

If you consider my project as helpful stuff, You can appreciate me or my hard work and time spent to create this helpful structure with buying me a coffee.

Buy Me A Coffee


  • Basic Authentication (Register/Login with hashed password)
  • Account confirmation with 4 (Changeable) digit OTP.
  • Email helper ready just import and use.
  • JWT Tokens, make requests with a token after login with
    header with value
    Bearer yourToken
    will be returned in Login response.
  • Pre-defined response structures with proper status codes.
  • Included CORS.
  • Book example with CRUD operations.
  • Validations added.
  • Included API collection for Postman.
  • Light-weight project.
  • Test cases with Mocha and Chai.
  • Code coverage with Istanbuljs (nyc).
  • Included CI (Continuous Integration) with Travis CI.
  • Linting with Eslint.

Software Requirements

  • Node.js 8+
  • MongoDB 3.6+ (Recommended 4+)

How to install

Using Git (recommended)

  1. Clone the project from github. Change "myproject" to your project name.
git clone ./myproject

Using manual download ZIP

  1. Download repository
  2. Uncompress to your desired directory

Install npm dependencies after installing (Git or manual download)

cd myproject
npm install

Setting up environments

  1. You will find a file named
    on root directory of project.
  2. Create a new file by copying and pasting the file and then renaming it to just
    cp .env.example .env
  3. The file
    is already ignored, so you never commit your credentials.
  4. Change the values of the file to your environment. Helpful comments added to
    file to understand the constants.

Project structure

├── app.js
├── package.json
├── bin
│   └── www
├── controllers
│   ├── AuthController.js
│   └── BookController.js
├── models
│   ├── BookModel.js
│   └── UserModel.js
├── routes
│   ├── api.js
│   ├── auth.js
│   └── book.js
├── middlewares
│   ├── jwt.js
├── helpers
│   ├── apiResponse.js
│   ├── constants.js
│   ├── mailer.js
│   └── utility.js
├── test
│   ├── testConfig.js
│   ├── auth.js
│   └── book.js
└── public
    ├── index.html
    └── stylesheets
        └── style.css

How to run

Running API server locally

npm run dev

You will know server is running by checking the output of the command

npm run dev
Connected to mongodb:YOUR_DB_CONNECTION_STRING
App is running ...

Press CTRL + C to stop the process.


will be your MongoDB connection string.

Creating new models

If you need to add more models to the project just create a new file in

and use them in the controllers.

Creating new routes

If you need to add more routes to the project just create a new file in

and add it in
it will be loaded dynamically.

Creating new controllers

If you need to add more controllers to the project just create a new file in

and use them in the routes.


Running Test Cases

npm test

You can set custom command for test at

file inside
property. You can also change timeout for each assertion with
parameter of mocha command.

Creating new tests

If you need to add more test cases to the project just create a new file in

and run the command.


Running Eslint

npm run lint

You can set custom rules for eslint in

file, Added at project root.

Bugs or improvements

Every project needs improvements, Feel free to report any bugs or improvements. Pull requests are always welcome.


This project is open-sourced software licensed under the MIT License. See the LICENSE file for more information.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.