Angular-style schematics for the NestJS framework, enabling generation of application components through a command-line interface.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Complete collection of 20+ code generators for NestJS applications, providing standardized component creation with TypeScript support, dependency injection setup, and consistent project structure.
All component schematics share common configuration options:
interface BaseSchematicOptions {
/** Component name */
name: string;
/** Target path for generation */
path?: string | Path;
/** Module to import the component into */
module?: Path;
/** Skip importing into module */
skipImport?: boolean;
/** Metadata type for module declaration */
metadata?: string;
/** Programming language (ts/js) */
language?: string;
/** Source root directory */
sourceRoot?: string;
/** Generate spec files */
spec?: boolean;
/** Spec file suffix */
specFileSuffix?: string;
/** Generate in flat structure */
flat?: boolean;
}
// Angular DevKit Types
type Path = string;
type Tree = import('@angular-devkit/schematics').Tree;
type SchematicContext = import('@angular-devkit/schematics').SchematicContext;
type Rule = (tree: Tree, context: SchematicContext) => Tree | Observable<Tree> | void;
type Observable<T> = import('rxjs').Observable<T>;Creates a complete NestJS application with project structure, configuration, and dependencies.
/**
* Generate a new NestJS application
* @param options - Application configuration options
* @returns Angular DevKit Rule for application generation
*/
function application(options: ApplicationOptions): Rule;
interface ApplicationOptions {
name: string | number;
author?: string;
description?: string;
directory?: string;
strict?: boolean;
version?: string;
language?: string;
packageManager?: 'npm' | 'yarn' | 'pnpm' | 'undefined';
dependencies?: string;
devDependencies?: string;
spec?: boolean;
specFileSuffix?: string;
}Usage Examples:
# Generate new application
nest new my-app
# With custom options
nest new my-app --strict --package-manager=yarnCreates a library within a monorepo structure.
/**
* Generate a Nest library for monorepo projects
* @param options - Library configuration options
* @returns Angular DevKit Rule for library generation
*/
function library(options: LibraryOptions): Rule;
interface LibraryOptions extends BaseSchematicOptions {
name: string;
}Usage Examples:
# Generate library
nest generate library shared
# With alias
nest g lib utilsCreates a sub-application within a monorepo.
/**
* Generate a sub-application for monorepo projects
* @param options - Sub-application configuration options
* @returns Angular DevKit Rule for sub-application generation
*/
function subApp(options: SubAppOptions): Rule;
interface SubAppOptions extends BaseSchematicOptions {
name: string;
}Usage Examples:
# Generate sub-application
nest generate sub-app api
# With alias
nest g app adminCreates NestJS modules with proper decorator setup and file structure.
/**
* Generate a Nest module
* @param options - Module configuration options
* @returns Angular DevKit Rule for module generation
*/
function module(options: ModuleOptions): Rule;
interface ModuleOptions extends BaseSchematicOptions {
name: string;
}Usage Examples:
# Generate module
nest generate module users
# Generate without importing to parent module
nest g mo products --skip-importCreates NestJS controllers with routing and dependency injection setup.
/**
* Generate a Nest controller
* @param options - Controller configuration options
* @returns Angular DevKit Rule for controller generation
*/
function controller(options: ControllerOptions): Rule;
interface ControllerOptions extends BaseSchematicOptions {
name: string;
}Usage Examples:
# Generate controller
nest generate controller auth
# Generate without spec file
nest g co users --no-spec
# Generate in specific path
nest g co admin/users --path=src/adminCreates NestJS services (providers) with dependency injection setup.
/**
* Generate a Nest service
* @param options - Service configuration options
* @returns Angular DevKit Rule for service generation
*/
function service(options: ServiceOptions): Rule;
interface ServiceOptions extends BaseSchematicOptions {
name: string;
}Usage Examples:
# Generate service
nest generate service users
# Generate with flat structure
nest g s auth --flatCreates generic NestJS providers.
/**
* Generate a Nest provider
* @param options - Provider configuration options
* @returns Angular DevKit Rule for provider generation
*/
function provider(options: ProviderOptions): Rule;
interface ProviderOptions extends BaseSchematicOptions {
name: string;
}Creates NestJS guards for route protection and authorization.
/**
* Generate a Nest guard
* @param options - Guard configuration options
* @returns Angular DevKit Rule for guard generation
*/
function guard(options: GuardOptions): Rule;
interface GuardOptions extends BaseSchematicOptions {
name: string;
}Usage Examples:
# Generate guard
nest generate guard auth
# Generate with alias
nest g gu rolesCreates NestJS interceptors for request/response transformation.
/**
* Generate a Nest interceptor
* @param options - Interceptor configuration options
* @returns Angular DevKit Rule for interceptor generation
*/
function interceptor(options: InterceptorOptions): Rule;
interface InterceptorOptions extends BaseSchematicOptions {
name: string;
}Usage Examples:
# Generate interceptor
nest generate interceptor logging
# Generate with alias
nest g itc transformCreates NestJS pipes for data transformation and validation.
/**
* Generate a Nest pipe
* @param options - Pipe configuration options
* @returns Angular DevKit Rule for pipe generation
*/
function pipe(options: PipeOptions): Rule;
interface PipeOptions extends BaseSchematicOptions {
name: string;
}Usage Examples:
# Generate pipe
nest generate pipe validation
# Generate with alias
nest g pi parse-intCreates NestJS exception filters for error handling.
/**
* Generate a Nest exception filter
* @param options - Filter configuration options
* @returns Angular DevKit Rule for filter generation
*/
function filter(options: FilterOptions): Rule;
interface FilterOptions extends BaseSchematicOptions {
name: string;
}Usage Examples:
# Generate filter
nest generate filter http-exception
# Generate with alias
nest g f validationCreates NestJS middleware for request processing.
/**
* Generate a Nest middleware
* @param options - Middleware configuration options
* @returns Angular DevKit Rule for middleware generation
*/
function middleware(options: MiddlewareOptions): Rule;
interface MiddlewareOptions extends BaseSchematicOptions {
name: string;
}Usage Examples:
# Generate middleware
nest generate middleware logger
# Generate with alias
nest g mi corsCreates NestJS WebSocket gateways for real-time communication.
/**
* Generate a Nest WebSocket gateway
* @param options - Gateway configuration options
* @returns Angular DevKit Rule for gateway generation
*/
function gateway(options: GatewayOptions): Rule;
interface GatewayOptions extends BaseSchematicOptions {
name: string;
}Usage Examples:
# Generate gateway
nest generate gateway chat
# Generate with alias
nest g ga eventsCreates GraphQL resolvers for NestJS GraphQL applications.
/**
* Generate a GraphQL resolver
* @param options - Resolver configuration options
* @returns Angular DevKit Rule for resolver generation
*/
function resolver(options: ResolverOptions): Rule;
interface ResolverOptions extends BaseSchematicOptions {
name: string;
}Usage Examples:
# Generate resolver
nest generate resolver user
# Generate with alias
nest g r postsCreates a complete CRUD resource with controller, service, DTOs, and entities.
/**
* Generate a complete CRUD resource
* @param options - Resource configuration options
* @returns Angular DevKit Rule for resource generation
*/
function resource(options: ResourceOptions): Rule;
interface ResourceOptions extends BaseSchematicOptions {
name: string;
type?: 'rest' | 'graphql-code-first' | 'graphql-schema-first' | 'microservice' | 'ws';
crud?: boolean;
isSwaggerInstalled?: boolean;
}Usage Examples:
# Generate REST resource with CRUD
nest generate resource posts --type=rest --crud
# Generate GraphQL resource
nest g res users --type=graphql-code-first
# Generate microservice resource
nest g res orders --type=microserviceCreates generic TypeScript classes.
/**
* Generate a TypeScript class
* @param options - Class configuration options
* @returns Angular DevKit Rule for class generation
*/
function classGenerator(options: ClassOptions): Rule;
interface ClassOptions extends BaseSchematicOptions {
name: string;
}Creates TypeScript interfaces.
/**
* Generate a TypeScript interface
* @param options - Interface configuration options
* @returns Angular DevKit Rule for interface generation
*/
function interfaceGenerator(options: InterfaceOptions): Rule;
interface InterfaceOptions extends BaseSchematicOptions {
name: string;
}Creates custom TypeScript decorators.
/**
* Generate a custom decorator
* @param options - Decorator configuration options
* @returns Angular DevKit Rule for decorator generation
*/
function decorator(options: DecoratorOptions): Rule;
interface DecoratorOptions extends BaseSchematicOptions {
name: string;
}Creates Angular client applications integrated with NestJS backend.
/**
* Generate an Angular client application
* @param options - Angular app configuration options
* @returns Angular DevKit Rule for Angular app generation
*/
function angularApp(options: AngularOptions): Rule;
interface AngularOptions extends BaseSchematicOptions {
name: string;
}Creates Nest CLI configuration files.
/**
* Generate Nest CLI configuration
* @param options - Configuration options
* @returns Angular DevKit Rule for configuration generation
*/
function configuration(options: any): Rule;Most schematics support short aliases for faster CLI usage:
| Schematic | Alias | Example |
|---|---|---|
application | - | nest g application my-app |
class | cl | nest g cl my-class |
controller | co | nest g co auth |
decorator | d | nest g d custom |
filter | f | nest g f exception |
gateway | ga | nest g ga chat |
guard | gu | nest g gu auth |
interceptor | itc | nest g itc logging |
interface | itf | nest g itf user |
library | lib | nest g lib shared |
middleware | mi | nest g mi cors |
module | mo | nest g mo users |
pipe | pi | nest g pi validation |
provider | pr | nest g pr config |
resolver | r | nest g r user |
resource | res | nest g res posts |
service | s | nest g s users |
sub-app | app | nest g app admin |
All schematics follow the Angular DevKit factory pattern:
/**
* Factory function pattern for all schematics
* @param options - Schematic-specific options
* @returns Angular DevKit Rule for tree transformation
*/
function schematicFactory<T>(options: T): Rule;