2.0.28 • Published 3 months ago

nodejs-backpack v2.0.28

Weekly downloads
-
License
CC BY-NC-ND 4.0
Repository
-
Last release
3 months ago

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

YouTube Tutorial

Watch the video

Quick Start (Rest APIs)

The quickest way to get started with nodejs-backpack is to utilize the executable to generate an REST APIs as shown below:

Step1: Create an empty directory:

mkdir NodeJs-REST-APIs

Step2: Enter into directory:

cd NodeJs-REST-APIs

Step3: 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.

    npm.io

  • Update .env > DB=mongodb+srv... with valid connection.

PORT=3000
DB="mongodb+srv://........mongodb.net/node_backpack"
JWT_SIGNATURE=node_backpack
HOST=http://localhost:3000

Step4: Run Command:

npm install

Step5: Run Command:

nodejs-backpack make:schema Tests

Step6: Run Command:

nodejs-backpack make:apis Test --url=tests --schema=Tests
  • Rename schema name in comand as per your requirement nodejs-backpack make:apis Test --url=tests --schema=Tests.
  • Example: nodejs-backpack make:apis ROUTE_NAME --url=ROUTE_URL --schema=SCHEMA_NAME.
  • Note: SCHEMA_NAME must exist in model directory /models/SCHEMA_NAME

Step7: Install 'nodemon' on global level for development purpose:

npm install nodemon -g

Step8: Now your APIs are ready to use and Server your project with:

npm run dev

Step9: Open Postman and create new collection and check the below apis:

  • Based on my command, nodejs-backpack make:apis Test --url=tests --schema=Tests.
  • ROUTE_NAME = Test
  • ROUTE_URL = tests
  • SCHEMA_NAME = Tests
  • Below are list of APIs created by commands .../api/ROUTE_URL:
  • Get List API: GET: http://localhost:3000/api/tests?page_no=1&page_limit=20&search= (Parameters: page_no, page_limit, search)
  • Get Detail API: GET: http://localhost:3000/api/tests/64a41036174844d0394e7b2f
  • Store API: POST: http://localhost:3000/api/tests (Body-Parameters: based on model schema)
  • Update API: PUT: http://localhost:3000/api/tests/64a41036174844d0394e7b2f (Body-Parameters: based on model schema)
  • Delete API: DELETE: http://localhost:3000/api/tests/64a41036174844d0394e7b2f

Quick Start (Authentication APIs)

The quickest way to get started with signup, register, forgot-password, reset-password, get-profile API's using nodejs-backpack is to utilize the executable to generate an REST APIs as shown below:

Step1: Run Command:

nodejs-backpack make:auth
  • Under ./routes/* 'IndexRoute.js' and 'AuthRoute.js' file will be create/updated.
  • 'AuthController.js' file will be create in the './controllers/AuthController.js' folder with all neccessary logics.
  • 'AuthMiddleware.js' file will be create in the './middleware/AuthMiddleware.js' folder with all neccessary JWT token verification logics.
  • mailtrap.js file will be create in the './config/mailtrap.js' folder where you can configure SMTP mail credentials.
  • Under ./models/* 'User.js' and 'ResetToken.js' file will be create.

Step2: Open Postman and create new collection and check the below apis:

  • Below are list of APIs created by commands .../api/ROUTE_URL:
  • Register API: POST: http://localhost:3000/api/register (Body-Parameters: first_name, last_name, email, password)
  • Login API: POST: http://localhost:3000/api/login (Body-Parameters: email, password)
  • Forgot Password API: POST: http://localhost:3000/api/forgot-password (Body-Parameters: email)
  • Reset Password API: POST: http://localhost:3000/api/reset-password (Body-Parameters: email, password, reset_token). Note: Forgot password reset link will contain 'reset_token' on mail.
  • Logout API: GET: http://localhost:3000/api/logout
  • Get Profile API: GET: http://localhost:3000/api/get-profile

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"
JWT_SIGNATURE=node_backpack
HOST=http://localhost:3000

Authors

2.0.28

3 months ago

2.0.26

3 months ago

2.0.27

3 months ago

2.0.24

3 months ago

2.0.25

3 months ago

2.0.22

3 months ago

2.0.23

3 months ago

2.0.21

3 months ago

2.0.15

5 months ago

2.0.16

5 months ago

2.0.14

5 months ago

2.0.19

5 months ago

2.0.17

5 months ago

2.0.20

5 months ago

2.0.13

9 months ago

2.0.12

10 months ago

2.0.11

10 months ago

2.0.10

10 months ago

2.0.9

10 months ago

2.0.8

10 months ago

2.0.7

10 months ago

2.0.6

10 months ago

2.0.5

10 months ago

2.0.4

10 months ago

2.0.3

10 months ago

2.0.2

10 months ago

2.0.1

10 months ago

2.0.0

10 months ago

1.0.16

10 months ago

1.0.15

10 months ago

1.0.14

10 months ago

1.0.13

10 months ago

1.0.12

10 months ago

1.0.11

10 months ago

1.0.10

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago