A feature-rich boilerplate for NodeJS RESTful API Development
This project provides a skeleton for any further RESTful API development. It implements the 3 Layer Architecture, which are Controller, Service Layer and Data Access Layer.
Controller will handle all stuffs related to requests and responses that are routed by Router. It will then call Service Layer methods which storing all business logic. The Data Access Layer will perform some operations on the database.
I am open for a good job or work contract. Contact me with my email quyetlm.work@gmail.com or LinkedIn Minh-Quyet Le.
- Authentication and Authorization: Bearer JWT Token
- No-SQL Database: MongoDB (can be installed locally or using a cloud version of MongoDB Atlas)
- Validation: Ajv JSON schema validator
- Loging: Morgan
- Testing: Unit Testing with Mocha and Chai
- CORS configuration.
- Light-weight
- CI/CD: Github Action
- Linting: Eslint.
- Error Handling: centralized error handling mechanism
- Code Quality: Codacy
- Node.js 8+
- MongoDB 5.0
- Clone the project
git clone https://github.com/lquyet/rest-api.git ./myproject
- Download repository
- Uncompress to your desired directory
cd myproject
npm install
-
You will find a file named
.env.example
on root directory of project. -
Create a new file by copying and pasting the file and then renaming it to just
.env
cp .env.example .env
-
Set the appropriate value for your environment variables.
rest-api
├─ .eslintrc.json
├─ .github
│ └─ workflows
│ ├─ codeql.yml
│ └─ node.js.yml
├─ .gitignore
├─ app.js
├─ LICENSE
├─ package-lock.json
├─ package.json
├─ README.md
└─ src
└─ v1
├─ authentication
│ ├─ checkAuth.js
│ └─ jwt.js
├─ controllers
│ ├─ productController.js
│ ├─ userController.js
│ └─ validators
│ ├─ productValidator.js
│ └─ userValidator.js
├─ database
│ ├─ models
│ │ ├─ productModel.js
│ │ └─ userModel.js
│ ├─ product.js
│ └─ user.js
├─ routes
│ ├─ productRoutes.js
│ └─ userRoutes.js
├─ services
│ ├─ productService.js
│ └─ userService.js
└─ test
├─ authTest.js
├─ config.js
├─ productTest.js
└─ utilityTest.js
npm start
npm test
npm run lint
npm run fix-lint
Custom rules for eslint can be found at .eslintrc.json
.
Feel free to report any bugs or improvements by setting a new Issue or Pull request.
This project is open-sourced software licensed under the MIT License.