A powerful, customizable, and developer-friendly Command Line Interface (CLI) tool designed to automate the scaffolding of Node.js/Express projects and Mongoose-backed CRUD (Create, Read, Update, Delete) components.
- 📂 Project Scaffolding: Initialize a complete Express.js boilerplate structure in one command.
- ⚡ Custom Template Engine: Uses clean template files (
templates/) instead of fragile inline code strings. - 🗃️ Smart Code Generators: Generates Mongoose models, controller logic, and Express routing files.
- 🧪 Field-Aware Validation: Pass field schemas through the CLI to automatically generate database models and request body validators.
- 🛠️ Extensible Architecture: Built on Commander.js for a robust command structure.
To install the CLI globally via npm:
npm install -g crud-builder-cliAlternatively, to run/link it locally from source:
-
Clone the repository:
git clone https://github.com/senuda-d/CRUD-generator-CLI.git cd CRUD-generator-CLI -
Install dependencies:
npm install
-
Link the package globally:
npm link
Now you can use the global command crud-builder anywhere on your system!
The CLI provides two main commands: init and generate.
To scaffold a new Node/Express application structure:
crud-builder init my-awesome-appThis command creates a new folder my-awesome-app with the following structure:
my-awesome-app/
├── src/
│ ├── app.js # Starter Express application
│ ├── controllers/ # Folder for controllers
│ ├── models/ # Folder for Mongoose models
│ └── routes/ # Folder for Express routes
├── .gitignore
└── package.json
Generate modular CRUD components for a database entity. You must navigate to your project directory and run:
crud-builder generate <EntityName> [options]| Flag | Description |
|---|---|
--model |
Generates a Mongoose schema model. |
--controller |
Generates a controller with standard CRUD request handlers. |
--route |
Generates REST routes mapping HTTP verbs to controllers. |
--crud |
Shortcut to generate model, controller, and routes (same as using all three flags). |
--fields <fields> |
Comma-separated list of field names and types (e.g. title:string,price:number). |
-
Generate a basic model and controller with validation fields:
crud-builder generate Task --model --controller --fields "title:string,completed:boolean,dueDate:date" -
Generate complete CRUD routes, models, and controllers in one go:
crud-builder generate User --crud --fields "email:string,age:number,active:boolean"
CRUD-generator-CLI/
├── bin/
│ └── cli.js # CLI entrypoint
├── commands/
│ ├── generate.js # Action handler for component generation
│ └── init.js # Action handler for project initialization
├── generators/
│ ├── controllerGenerator.js
│ ├── modelGenerator.js
│ ├── projectGenerator.js
│ └── routeGenerator.js
├── templates/ # Source templates used by generators
│ ├── app.template.js
│ ├── controller.template.js
│ ├── model.template.js
│ └── route.template.js
├── utils/
│ ├── fileWriter.js
│ ├── nameHelper.js
│ └── templateEngine.js # Custom regex-based replacement helper
└── tests/ # Automated tests
├── generators.test.js
└── templateEngine.test.js
The project utilizes the native Node.js test runner (introduced in Node v18+), requiring no third-party test runners or heavy testing frameworks.
To execute the test suite:
npm testThis runs both unit tests for the template engine and integration tests for the generators.
Contributions are what make the open-source community an amazing place to learn, inspire, and create.
- Fork the Project.
- Create your Feature Branch (
git checkout -b feature/AmazingFeature). - Commit your changes (
git commit -m 'feat: add some AmazingFeature'). - Push to the Branch (
git push origin feature/AmazingFeature). - Open a Pull Request.
Distributed under the MIT License. See LICENSE for more information.