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.

CommandShortCreates
nest generate module productsnest g mo productsproducts.module.ts (and imports it in AppModule)
nest generate controller productsnest g co productsController + spec
nest generate service productsnest g s productsService + spec
nest generate guard auth/rolesnest g gu auth/rolesGuard
nest generate pipe common/trimnest g pi common/trimPipe
nest generate resource ordersnest g res ordersModule + 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-run

Example 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.