Careeroza
Nest CLI Commands
Generate Instead of Typing
The CLI creates files with the right names, adds a test file and registers the class in the nearest module.
| Command | Short | Creates |
|---|---|---|
nest generate module products | nest g mo products | products.module.ts (and imports it in AppModule) |
nest generate controller products | nest g co products | Controller + spec |
nest generate service products | nest g s products | Service + spec |
nest generate guard auth/roles | nest g gu auth/roles | Guard |
nest generate pipe common/trim | nest g pi common/trim | Pipe |
nest generate resource orders | nest g res orders | Module + controller + service + DTOs + entity |
Useful Flags
Example
--dry-run shows what would be created; --no-spec skips test files; --flat skips the extra folder.
nest g s products --dry-runExample output
CREATE src/products/products.service.spec.ts (467 bytes) CREATE src/products/products.service.ts (92 bytes) UPDATE src/products/products.module.ts (262 bytes) NOTE: The "dryRun" flag means no changes were made.