npm

npm’s 2019 JavaScript ecosystem survey analysis is now available! Get your copy here »

build-express-api

1.0.6 • Public • Published

Build Express Api

A Command line interface for instantly building an express rest api.
Create controllers, models and add routes in matter of seconds.

npm version

This CLI only supports Node 6 and over.

Installation

Install it once globally:

$ npm install -g build-express-api

Getting Started

Initializing the application structure

$ mkdir my-app
cd my-app
$ build-express-api init

Directory structure

my-app
├── package.json
├── rest
    └── controllers
    └── models
    └── server.js

Install all the needed dependencies:

$ npm install

Note: when running all of the further commands, please stay in the my-app directory

Creating a new controller

$ build-express-api create-controller

The CLI will now take you through series of questions, the example of building a new controller would be:

Creating a plain controller

You can choose the plain controller or custom routes controller from the menu.

Plain controller just creates a controller with built in routes in rest/controllers/controllerName.js.

Custom routes controller allows you to manually add your routes, the example of building custom routes controller would be:

Creating a custom routes controller

Note: make sure that you write the routes in the correct (strict JSON) format such as:

{"routeName":"METHOD"}

When the controller is created it will automatically be imported in server.js file

Adding routes to a controller

$ build-express-api add-routes <controllerName>

Example:

Adding routes to a controller

Creating new model

$ build-express-api create-model

Example:

Creating new model

Note: When creating new model, you don't need to provide the properties in strict JSON format, just separate them with the comma

Also models are not automatically imported in server.js, so you will need to import them manually.

This CLI supports only mongoose models for now.

Note: The experience this CLI provides does not work as smooth in Git Bash terminal, since it is not an interactive terminal, but if you are using Git Bash inside VS Code, then there are no problems, I found no complications using any other terminal.

install

npm i build-express-api

Downloadsweekly downloads

4

version

1.0.6

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability