nodejs-module-generator
v1.1.0
Published
A CLI tool to generate a Node.js project structure with dynamic modules.
Downloads
21
Maintainers
Readme
Node.js Module Generator
nodejs-module-generator
is a CLI tool designed to dynamically generate module structures for Node.js projects using Sequelize ORM. Create boilerplate code with a simple command.
Installation
To install the package globally, run:
npm install -g nodejs-module-generator
Initialize Sequelize
Initialize Sequelize with default configuration in the src/sequelize directory:
npx nmg init
This command installs Sequelize, sets up the necessary configuration files, and creates the required directories (models, migrations, seeders, config) inside src/sequelize.
Generate a Module
Generate a new module with controllers, services, models, and interfaces:
npx nmg generate:module <modulename>
This command creates a module with the following structure:
src
modules
<modulename>
controllers
create.controller.js
update.controller.js
get.controller.js
services
create.service.js
update.service.js
get.service.js
models
<modulename>.model.js
interfaces
<modulename>.interface.js
Generate a Sequelize Model
Generate a new Sequelize model in the specified module. Hyphenated names will be converted to camelCase:
npx nmg model <moduleName>:<modelName> --attributes <attributes>
Options
- moduleName: The name of the module where the model should be created.
- modelName: The name of the model. Hyphens will be converted to camelCase.
- --attributes: A comma-separated list of attributes and their types. For example: username:string,email:string,age:integer.
Example
To generate a model named admin-users in the admin module with attributes username, email, and age, run:
npx nmg model admin:admin-users --attributes username:string,email:string,age:integer
This command will:
- Create adminUsers.model.js in the src/modules/admin/models directory.
- Define the model with attributes username, email, and age.
- Add the model reference to the src/sequelize/models/index.js file.
Configuration
The generator creates a basic structure which you can further customize according to your project's needs.
Please make sure to update tests as appropriate.
License
This project is licensed under the MIT License.
License
Created by Pritey Mehta.
Acknowledgments
Inspired by Sequelize ORM for Node.js.