crud-npm
v1.0.0
Published
> A powerful Gii-style CLI and GUI for scaffolding production-ready NestJS CRUD resources with TypeORM and Swagger.
Maintainers
Readme
🚀 NestJS CRUD Generator
A powerful Gii-style CLI and GUI for scaffolding production-ready NestJS CRUD resources with TypeORM and Swagger.
Features
- 🖥️ Gii-Style Visual Designer: A local web interface to visually design your entities.
- ✨ Zero-Config: Runs immediately without complex setup.
- 🔌 Swagger Ready: Generated DTOs and Controllers come pre-decorated with
@ApiProperty,@ApiOperation, etc. - 🛠️ Advanced Entity Modeling:
- Define Relationships (OneToOne, OneToMany, ManyToOne, ManyToMany).
- Set Primary Keys, Field Lengths, and Uniqueness.
- 📂 Flexible Output: Override destination paths per resource (e.g., separate modules folder).
- 🐘 TypeORM & MySQL: Built-in support for generating
.envandDatabaseModule.
Installation
Install globally or as a dev dependency:
# Global
npm install -g crud-npm
# OR
pnpm add -g crud-npm
# Dev Dependency (Recommended)
pnpm add -D crud-npmQuick Start (GUI)
The easiest way to use the generator is via the visual interface.
Run the UI command:
crud-gen ui # OR if installed locally npx crud-gen uiThis will open
http://localhost:4000in your browser.Database Setup:
- Go to the Database Setup tab.
- Enter your MySQL credentials.
- Click Generate Configuration.
- This creates a
.envfile andsrc/database/database.module.ts.
Generate a Resource:
- Go to CRUD Resource.
- Resource Name: Enter the PascalCase name (e.g.,
Product). - Table Name: (Optional) e.g.,
shop_products. - Fields: Add fields like
name,price,description.- Tick 'PK' for Primary Key.
- Tick 'Len' to set varchar length (e.g., 255).
- Use 'Relation' dropdown to define relations (e.g., ManyToOne to
User).
- Paths: (Optional) Override where files are generated.
- Click Generate All Files.
CLI Usage
You can also use the command line directly.
# Initialize Config (Optional)
crud-gen init
# Generate Database Config
crud-gen db:setup
# Launch UI
crud-gen uiGenerated Structure
A typical resource generation creates:
src/
├── entities/
│ └── product.entity.ts # TypeORM Entity with Swagger & Relations
├── dto/
│ └── product/
│ ├── create-product.dto.ts # DTO with Validation & Swagger
│ └── update-product.dto.ts
├── controllers/
│ └── product.controller.ts # Standard CRUD Headers + Swagger
├── services/
│ └── product.service.ts # TypeORM Repository Logic
└── modules/
└── product.module.ts # Module wiringPeer Dependencies
This package relies on the following being installed in your host project:
@nestjs/common@nestjs/core@nestjs/typeorm@nestjs/swaggertypeormclass-validator
License
Cross-Platform & Docker Support
- Windows/Linux/Mac: Fully supported. Path handling is normalized for all operating systems.
- Docker: Works out of the box. Ensure to expose port
4000if using the GUI:docker run -p 4000:4000 -v $(pwd):/app -w /app node:18 npx crud-npm ui
License
MIT © Anjan
