NodeJs Backpack
NodeJs Backpack is a powerful tool designed to simplify the development of Node.js REST APIs with ease and precision. It provides a streamlined workflow by automatically generating Mongoose schemas and handling the necessary configurations in your project.
With just a few simple commands, NodeJs Backpack can create REST API components such as controllers and routes, while also ensuring route validation is implemented flawlessly. Additionally, NodeJs Backpack offers a command to generate sample files, providing a solid starting point for your project.
With NodeJs Backpack, you can quickly set up your project and focus on building your APIs, letting the tool handle the repetitive tasks and allowing you to follow a smooth development process.
Installation
Install package globally with npm
npm install nodejs-backpack -g
Features
- Robust REST APIs
- Focus on optimized code
- Auto file creation for schemas, routes, controllers and validations
- helpers (modelsParams, appendParams, etc)
- Mongoose DB support,
- AppendParams for append data in APIs using Mongoose schema
- Executable for generating applications quickly
- Auto create logic for API CRUD
Quick Start
The quickest way to get started with nodejs-backpack is to utilize the executable to generate an REST APIs as shown below:
Create an empty directory:
mkdir NodeJs-REST-APIs
Enter into directory:
cd NodeJs-REST-APIs
Run Command:
nodejs-backpack sample:files
- File "
sample-app.js
", "sample-package.json
" & ".sample-env
" created in the root directory. - Rename sample files to "
app.js
", "package.json
" & ".env
" which are created in the root directory. - Update .env >
DB=mongodb+srv...
with valid connection.
PORT=3000
DB="mongodb+srv://........mongodb.net/node_backpack"
Run Command:
npm install
Run Command:
nodejs-backpack make:schema Users
Run Command:
nodejs-backpack make:apis User --url=users --schema=Users
- Rename schema name in comand as per your requirement nodejs-backpack make:apis User --url=users --schema=Users.
- Example: nodejs-backpack make:apis ROUTE_NAME --url=ROUTE_URL --schema=SCHEMA_NAME.
- Note:
SCHEMA_NAME
must exist in model directory /models/SCHEMA_NAME
Now your APIs are ready to use and Server your project with:
npm run dev
Step5: Open Postman and create new collection and check the below apis:
- Based on my command,
nodejs-backpack make:apis
User
--url=users
--schema=Users
. - ROUTE_NAME =
User
- ROUTE_URL =
users
- SCHEMA_NAME =
Users
- Below are list of APIs created by commands
.../api/ROUTE_URL
: - Get List API:
GET:
http://localhost:3000/api/users?page_no=1&page_limit=20&search=
- Get Detail API:
GET:
http://localhost:3000/api/users/64a41036174844d0394e7b2f
- Store API:
POST:
http://localhost:3000/api/users
- Update API:
PUT:
http://localhost:3000/api/users/64a41036174844d0394e7b2f
- Delete API:
DELETE:
http://localhost:3000/api/users/64a41036174844d0394e7b2f
Environment Variables
To run this project, you will need to add the following environment variables to your .env file
PORT=3000
DB="mongodb+srv://........mongodb.net/node_backpack"
Authors