A boilerplate for REST API Development with Node.js, Express, and MongoDB
A ready-to-use boilerplate for REST API Development with Node.js, Express, and MongoDB
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.
This advert was placed by GitAds
If you consider my project as helpful stuff, You can appreciate me or my hard work and time spent to create this helpful structure with buying a coffee for me. I would be very thankful if you buy me a coffee, please buy me a coffee :smile:.
Authorizationheader with value
yourTokenwill be returned in Login response.
git clone https://github.com/maitraysuthar/rest-api-nodejs-mongodb.git ./myproject
cd myproject npm install
.env.exampleon root directory of project.
bash cp .env.example .env
.envis already ignored, so you never commit your credentials.
.env.examplefile to understand the constants. ## Project structure
sh . ├── app.js ├── package.json ├── bin │ └── www ├── controllers │ ├── AuthController.js │ └── BookController.js ├── models │ ├── BookModel.js │ └── UserModel.js ├── routes │ ├── api.js │ ├── auth.js │ └── book.js ├── middlewares │ ├── jwt.js ├── helpers │ ├── apiResponse.js │ ├── constants.js │ ├── mailer.js │ └── utility.js ├── test │ ├── testConfig.js │ ├── auth.js │ └── book.js └── public ├── index.html └── stylesheets └── style.css## How to run
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.
YOUR_DB_CONNECTION_STRINGwill be your MongoDB connection string.
If you need to add more models to the project just create a new file in
/models/and use them in the controllers.
If you need to add more routes to the project just create a new file in
/routes/and add it in
/routes/api.jsit will be loaded dynamically.
If you need to add more controllers to the project just create a new file in
/controllers/and use them in the routes.
You can set custom command for test at
scriptsproperty. You can also change timeout for each assertion with
--timeoutparameter 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.
npm run lint
You can set custom rules for eslint in
.eslintrc.jsonfile, 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.