A Boilerplate/Starter Project for building RESTful APIs using Node.js, Express, and Mongoose.
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
└─
- 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
Clone the repo:
git clone https://github.com/CemBdc/nodejs-restapi.git
cd nodejs-restapi
Install the dependencies:
npm install
Set the environment variables:
cp .env.example .env
# open .env and modify the environment variables (if needed)
npm run start
# lint code with ESLint
npm run lint
# run all tests with Mocha
npm run test
# run test coverage
npm run test:coverage
Contributions are more than welcome! Please check out the contributing guide.