CE
cemasil/nodejs-restapi
⌛️ Boilerplate for API backends with Node.js and Express.
Nodejs-Restapi-Boilerplate
A Boilerplate/Starter Project for building RESTful APIs using Node.js, Express, and Mongoose.
Directory structure
Overview
Project src structure directories.
src/
├─ config/
│ ├─ config.js
├─ controller.js
│ ├─ controller.index.js
│ ├─ userController.js
├─ loader/
│ ├─ express.js
│ ├─ mongoose.js
│ ├─ server.js
├─ middlewares/
│ ├─ middlewares.index.js
│ ├─ validator.js
├─ routes/
│ ├─ routes.index.js
│ ├─ routes.js
│ ├─ userRoute.js
├─ utils/
│ ├─ requestUtil.js
│ ├─ utils.index.js
test/
├─ example.test.js
├─ userController.test.js
└─
Features
- ES9: latest ECMAScript features
- NoSQL database: MongoDB object data modeling using Mongoose
- Authentication and authorization: using jsonwebtoken
- Validation: request data validation using Joi
- Logging: //TODO: winston
- Testing: unit and integration tests using Mocha Chai
- Error handling: centralized error handling mechanism
- API documentation: //TODO: swagger
- Dependency management: with Npm
- Environment variables: using dotenv
- Security: set security HTTP headers using helmet
- Santizing: sanitize request data against xss and query injection
- CORS: Cross-Origin Resource-Sharing enabled using cors
- Compression: //TODO: gzip compression with compression
- CI: continuous integration with Travis CI
- Docker support
- Code coverage: using coveralls
- Code quality: with Codacy
- Git hooks: with husky
- Linting: with ESLint and Prettier
- Editor config: consistent editor configuration using EditorConfig
Getting Started
Installation
Clone the repo:
git clone https://github.com/CemBdc/nodejs-restapi.git
cd nodejs-restapiInstall the dependencies:
npm installSet the environment variables:
cp .env.example .env
# open .env and modify the environment variables (if needed)Commands
Running locally:
npm run startLint
# lint code with ESLint
npm run lintTest
# run all tests with Mocha
npm run test
# run test coverage
npm run test:coverageContributing
Contributions are more than welcome! Please check out the contributing guide.
Inspirations
- danielfsousa/express-rest-es2017-boilerplate
- madhums/node-express-mongoose
- kunalkapadia/express-mongoose-es6-rest-api
License
On this page
Languages
JavaScript99.4%Shell0.6%
Contributors
MIT License
Created March 29, 2020
Updated June 3, 2024