Skip to content
This repository has been archived by the owner on Aug 8, 2022. It is now read-only.

This repository is a template to avoid rewriting all the basic authentication code for REST API's built with Express.js, MongoDB.

License

Notifications You must be signed in to change notification settings

stackinflow/node-rest-api-starter

Repository files navigation

Node.js REST API starter

stackinflow Codacy Badge Build Status GitHub issues Twitter URL Gitter GitHub repo size Created Badge Updated Badge

Buy Me A Coffee

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

  1. Why this template
  2. Project architecture and Directories Structure
  3. Tech stack
  4. Install and configure Node.js
  5. MongoDB installation and configuration
  6. Setup and Run the Project
  7. Setup GitHub actions
  8. Authors
  9. 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 Ubuntu based operating system, for other operating systems please refer to respective websites.

For manual setup docs, please refer here,

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
  1. Setup environment variables Rename the .env.example as .env and 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

  1. Place your application's Database credentials and config inside the .env.

  2. Install Prettier and ESLint in VS Code

  3. Google and Facebook client details, check out this article for generating client details

  4. Run the project with nodemon (dev server)

npm run dev

or Run as normal project (prod server)

npm start
  1. Run tests
npm test

After running the project, checkout swagger ui at http://localhost:7000/explorer/#/

Setup GitHub actions

Refer this page

Authors

image image
LinkedIn GitHub Twitter Medium LinkedIn GitHub Twitter Medium

Contributing

Check Contributing file

About

This repository is a template to avoid rewriting all the basic authentication code for REST API's built with Express.js, MongoDB.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published