NodeJs & Mongodb - API end points
This is a basic API skeleton written in JavaScript ES6. Very useful to building a RESTful web APIs
This project will run on NodeJs using MongoDB as database. I had tried to maintain the code structure easy as any beginner can also adopt the flow and start building an API. Project is open for suggestions, Bug reports and pull requests. ]
- Pre-defined response structures with proper status codes.
- Included CORS.
- Book example with CRUD operations.
- Included API collection for Postman. LINK
- Light-weight project.
- Test cases with Mocha and Jest.
- Node.js 15+
- Clone the project from github. Change "myproject" to your project name.
git clone https://github.com/SakibHasanCse/Nodejs-Rest-Api.git ./myproject
- Download repository
- Uncompress to your desired directory
cd myproject
npm install || yarn add
- You will find a file named
congig/config.env
on root directory of project.
.
├── app.js
├── package.json
├── bin
│ └── www
├── controllers
│ └── Book.js
├── models
│ ├── Book.js
├── routes
│ └── book.js
├── helpers
│ ├── apiResponse.js
└── test
├── testConfig.js
└── book.test.js
npm run dev
You will know server is running by checking the output of the command npm run dev
Connected to mongodb:YOUR_DB_CONNECTION_STRING
App is running ...
Press CTRL + C to stop the process.
Note: YOUR_DB_CONNECTION_STRING
will be your MongoDB connection string.
npm test
You can set custom command for test at package.json
file inside scripts
property. You can also change timeout for each assertion with --timeout
parameter of mocha command.
If you need to add more test cases to the project just create a new file in /test/
and run the command.
You can set custom rules for eslint in .eslintrc.json
file, Added at project root.
Every project needs improvements, Feel free to report any bugs or improvements. Pull requests are always welcome.
This project is open-sourced software licensed under the MIT License. See the LICENSE file for more information.