A boilerplate for building RESTful APIs using Node.js, Express and Mongoose.
- 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
Get started with the below steps:
- Clone the repo:
git clone https://github.com/shraddha319/REST-API-boilerplate.git
cd REST-API-boilerplate
- Install the dependencies
npm install
- Set the environment variables
cp .env.example .env
# modify the environment variables in .env if required
The environment variables can be found and modified in the .env file.
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 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.
List of available endpoints:
POST /auth/login
- login user
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