node-rest-api-starter
node-rest-api-starter copied to clipboard
This repository is a template to avoid rewriting all the basic authentication code for REST API's built with Express.js, MongoDB.
Node.js REST API starter
This repository is a template to avoid rewriting all the basic authentication code for REST API's built with Express.js, MongoDB.
Table of contents
- Why this template
- Project architecture and Directories Structure
- Tech stack
- Install and configure Node.js
- MongoDB installation and configuration
- Setup and Run the Project
- Setup GitHub actions
- Authors
- Contributing
Why this template
- This repository includes setup of all basic things required to start a MEAN/MERN stack backend
- Environments setup
- Connection to database(MongoDB)
- Admin routes for handling users
- Authentication - fully handled
- Social auth includes Facebook and Google OAuth2 authorization
- Provides clean structured code
- Mocha Tests to ensure API is working
- Email templates for account verification and password reset
- Token based email verification and OTP based password reset
- Body field validators
Project architecture and Directories Structure
.
├── api
│ └── v1
│ ├── controllers
│ │ ├── auth.js
│ │ ├── token.js
│ │ └── user.js
│ ├── middlewares
│ │ └── auth.js
│ ├── models
│ │ ├── auth.js
│ │ ├── token.js
│ │ └── user.js
│ ├── routes
│ │ ├── admin
│ │ │ └── auth.js
│ │ ├── auth.js
│ │ └── user.js
│ └── utils
│ ├── constants
│ │ ├── account.js
│ │ ├── collection_names.js
│ │ ├── email_token.js
│ │ ├── error_messages.js
│ │ ├── headers.js
│ │ └── success_messages.js
│ ├── constants.js
│ ├── response.js
│ ├── send_email.js
│ ├── templates
│ │ └── verify_email.pug
│ └── validators.js
├── assets
│ └── banner-node-rest-api.png
├── core
│ ├── config.js
│ ├── db.js
│ ├── helpers.js
│ ├── jwt.js
│ ├── print_env.js
│ └── server.js
├── index.js
├── keys
│ ├── private.pem
│ ├── privater.pem
│ ├── public.pem
│ └── publicr.pem
├── package.json
├── package-lock.json
├── public
│ └── images
├── README.md
├── tests
│ └── v1
│ ├── auth.js
│ └── test.js
└── utils
├── ASSET_LICENSES
├── bash_scripts
│ ├── mongodb_setup.sh
│ ├── node_setup.sh
│ └── setup_project.sh
├── CONTRIBUTING.md
├── docs
│ ├── gh_actions.md
│ ├── setup_mongo.md
│ ├── setup_node.md
│ └── setup_project.md
├── node-rest-api-auth.postman_collection.json
└── swagger
├── api
│ └── v1
│ ├── auths.yaml
│ └── paths.yaml
├── schemas
└── swagger.yaml
Tech stack
Node.js, Express.js, MongoDB, JWT, Pug.js, Sendgrid mail
Dependencies
Check package.json file
Tests
Tests are written using Mocha and Chai, here
CI/CD
Runs Tests on pull request is raised
Project setup
Go ahead into the root directory of the repository and follow the below instructions
Note: Setup scripts and docs are written only for
Ubuntubased operating system, for other operating systems please refer to respective websites.
For manual setup docs, please refer here,
- MongoDB
- Node.js
- Project & keys
Installation of Node.js
Execute the below command in terminal
bash utils/bash_scripts/setup_node.sh
MongoDB installation and configuration
Execute the below command in terminal
bash utils/bash_scripts/setup_mongo.sh
Setup and run the project
Execute the below command in terminal
bash utils/bash_scripts/setup_project.sh
- Setup environment variables
Rename the
.env.exampleas.envand fill up your details there.
SendGrid
Create an account at SendGrid SendGrid.
Create a new API Key here
Verify a sender email and use that email in the .env file, to verify click here
-
Place your application's Database credentials and config inside the
.env. -
Google and Facebook client details, check out this article for generating client details
-
Run the project with nodemon (dev server)
npm run dev
or Run as normal project (prod server)
npm start
- Run tests
npm test
After running the project, checkout swagger ui at http://localhost:7000/explorer/#/
Setup GitHub actions
Refer this page
Authors
![]() |
![]() |
Contributing
Check Contributing file

