Coder Social home page Coder Social logo

build-express-api's Introduction

Build Express Api

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

Build Status 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
├── beaConfig.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

Configuring CLI with active projects

If you already started a project, and have a different application structure, no worries.

$ build-express-api create-config

or

$ build-express-api cconfig

This command only creates a beaConfig.json file in the root directory, without creating a ./rest folder.
Use this file to configure the CLI on where to store the controllers, models, and where is the server.js or app.js file

beaConfig.json initially looks like this

{
  "serverPath": "./rest/server.js",
  "controllersPath": "./rest/controllers",
  "modelsPath": "./rest/models"
}

Configure the paths to your application, so the CLI knows how to execute the commands.

Creating a new controller

$ build-express-api create-controller

or

$ build-express-api cc

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 the path provided in beaConfig.json file.

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 the file provided in the beaConfig.json as the serverPath.

Adding routes to a controller

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

or

$ build-express-api ar <controllerName>

Example:

Adding routes to a controller

Creating new model

$ build-express-api create-model

or

$ build-express-api cm

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.

Feel free to post issues if you run into any.

build-express-api's People

Contributors

ognjengt avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.