Skip to content

shraddha319/REST-API-boilerplate

Repository files navigation

REST API Boilerplate

A boilerplate for building RESTful APIs using Node.js, Express and Mongoose.

Features

  • Error Handling: centralized error handling mechanism
  • Authentication and Authorization: using JWT
  • NoSQL database: MongoDB
  • Object Data Modeling:using Mongoose
  • Validation: using Joi
  • Testing: unit tests using Jest
  • CORS: Cross-Origin Resource Sharing enabled using cors
  • API Documentation: using Swagger UI express
  • Environment Variables: using dotenv
  • Dependency Management: using npm
  • Linting: using ESLint and Prettier

Quick Start

Get started with the below steps:

  1. Clone the repo:
git clone https://github.com/shraddha319/REST-API-boilerplate.git
cd REST-API-boilerplate
  1. Install the dependencies
npm install
  1. Set the environment variables
cp .env.example .env

# modify the environment variables in .env if required

Environment Varibles

The environment variables can be found and modified in the .env file.

Commands

The following commands can be found under scripts in package.json.

Run locally:

npm run dev

Run in production:

npm run start

Testing:

# run all tests
npm run test

# run all tests in watch mode
npm run test:watch

# run test coverage
npm run test:coverage

Linting:

# run ESLint
npm run lint

# fix ESLint errors
npm run lint:fix

API Documentation

API documentation is done with the help of Swagger UI express package. Run the server and go to the /docs route on your browser. The src/docs folder contains swagger config and all the schema and route specifications.

API Endpoints

List of available endpoints:

Auth routes:

POST /auth/login - login user

User routes:

POST /users - create user
GET /users/:userId - get user by ID
POST /users/:userId - update user by ID
DELETE /users/:userId - delete user by ID

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages