1.2.0 • Published 7 months ago

nemscaf v1.2.0

Weekly downloads
-
License
ISC
Repository
github
Last release
7 months ago

NEMSCAF CLI Tool

NEMSCAF (Node Express MongoDB) is a Command Line Interface (CLI) tool designed to scaffold Node.js, Express, and MongoDB projects efficiently. This tool allows developers to generate a boilerplate project with customizable features like authentication and data validation, ensuring a faster and standardized development process.


Features

  • Quick Setup: Generate a fully functional project with just one command.
  • Customizable Authentication: Choose between JWT (default) or PassportJS for user authentication.
  • Validation Options: Integrate Joi for request data validation to sanitize and structure user input.
  • Modular and Scalable Codebase: The boilerplate is designed with clean, modular, and scalable architecture.

Installation

To install the CLI globally, run:

npm install -g nemscaf

Usage

After installation, you can use the nemscaf command to create and manage projects.

General Command

nemscaf

Displays the general help and available commands:

Usage: nemscaf [options] [command]

A Command Line Interface (CLI) tool to scaffold Node.js, Express, and MongoDB projects with customizable boilerplate code for authentication and validation.

Options:
  -V, --version               output the version number
  -h, --help                  display help for command

Commands:
  create [options] <dirName>  Generate a new project with Node.js, Express, and MongoDB. Customize the project setup with additional options for authentication and validation.
  add <type> <name> [options] Add components like models, controllers, and routes to your project.
  help [command]              display help for command

Create Command

The create command generates a new Node.js, Express, and MongoDB project.

Usage

nemscaf create [options] <dirName>

Arguments

ArgumentDescription
dirNameName of the project directory.

Options

OptionDescription
--passportIntegrate PassportJS for user authentication.
--joiInclude Joi for request data validation.
-h, --helpDisplay help for the create command.

Examples

  1. Default Setup
    Without any options, the CLI sets up a project using JWT for authentication and excludes input validation.

    nemscaf create my-app
  2. With PassportJS Authentication
    Includes PassportJS for handling user authentication.

    nemscaf create my-app --passport
  3. With Joi Validation
    Adds Joi for request data validation.

    nemscaf create my-app --joi
  4. With Both PassportJS and Joi
    Combines PassportJS authentication with Joi validation.

    nemscaf create my-app --passport --joi

Add Command

The add command is used to generate components such as models, controllers, and routes for your project.

Usage

nemscaf add <type> <name> [options]

Supported Types

  1. Models Add a new model to the project.

    Usage:

    nemscaf add model <modelName> [attributes:dataTypes...]

    Arguments:

    ArgumentDescription
    modelNameName of the model.
    attributes:dataTypesSchema attributes with Mongoose data types (optional).

    Example:

    nemscaf add model Product name:String price:Number available:Boolean

    If no attributes are given in the command then it will generate an empty schema which users can define by itself.

  2. Controllers Add a new controller for a specific model.

    Usage:

    nemscaf add controller <modelName> [actions...]

    Arguments:

    ArgumentDescription
    modelNameName of the model for which the controller will be created.
    actionsActions to define in the controller (e.g., :create, :index).

    Supported Actions:

    ActionDescription
    :createCreates a new record in the database.
    :indexRetrieves all records from the database.
    :showRetrieves a single record by its ID.
    :updateUpdates an existing record.
    :destroyDeletes a specific record by its ID.

    Example:

    nemscaf add controller Product :create :index :update :destroy

    This command generates a controller for an already defined model in the project. Additionally, if a user needs to add specific actions to an existing controller, they can do so by specifying the required actions within the same command.

  3. Routes Add a new route for a specific controller.

    Usage:

    nemscaf add route <controllerName> [actions...]

    Arguments:

    ArgumentDescription
    controllerNameName of the controller for which the routes will be generated.
    actionsActions to define in the routes as an api endpoints (e.g., :create, :index)

    Example:

    nemscaf add route Product :create :index :show

    This command generates routes for HTTP methods like GET, POST, and DELETE, linking them to the appropriate controller actions. If no actions are provided it will geenrate the endpoints on the already defined actions inside the controller.


Scaffold Command

The scaffold command is used to generate the model, controller and routes for the given attributes. It will generate all the CRUD endpoints.

Usage

nemscaf scaffold <modelName> <attributes:dataTypes>

Arguments:

ArgumentDescription
modelNameName of the model.
attributes:dataTypesSchema attributes with Mongoose data types.

Example:

nemscaf scaffold Product name:String price:Number available:Boolean

Project Structure

The generated project includes the following structure:

my-app/
├── src/
│   ├── controllers/
│   ├── middlewares/
│   ├── models/
│   ├── routes/
│   └── utils/
├── .env
├── .gitignore
├── index.js
├── package.json
└── README.md

Key Files and Directories

  • src/controllers: Handles the logic for each route.
  • src/middlewares: Middleware functions for authentication, validation, etc.
  • src/models: Mongoose schemas and models for MongoDB.
  • src/routes: Route definitions for the API.
  • src/utils: Utility functions (e.g., token generation, error handling).

Contributing

Contributions, issues, and feature requests are welcome!
Feel free to check the issues page or submit a pull request.


License

This project is licensed under the MIT License - see the LICENSE file for details.


Author

Developed by Bharat Raj Verma.

1.2.0

7 months ago

1.1.2

7 months ago

1.1.1

7 months ago

1.1.0

7 months ago

1.0.1

8 months ago

1.0.0

8 months ago