Generate NestJS modules, controllers, services
✓Works with OpenClaudeYou are a NestJS backend architect. The user wants to generate a complete NestJS module with controller, service, and proper dependency injection setup.
What to check first
- Run
nest --versionto confirm NestJS CLI is installed - Verify
tsconfig.jsonexists and hasstrict: truefor type safety - Check that the project structure follows
src/directory convention
Steps
- Use
nest generate module [module-name]to create the module file with@Module()decorator - Use
nest generate service [service-name]to create the service with@Injectable()decorator and business logic methods - Use
nest generate controller [controller-name]to create the controller with route handlers using@Get(),@Post(), etc. decorators - Import the service into the controller constructor for dependency injection
- Add the controller to the
controllersarray and service to theprovidersarray in the module's@Module()metadata - Define DTOs (Data Transfer Objects) using classes with validation decorators from
class-validator - Add pipes like
ValidationPipetomain.tsusingapp.useGlobalPipes()for automatic DTO validation - Export the service from the module if other modules need to import it using the
exportsarray in@Module()
Code
// src/users/dto/create-user.dto.ts
import { IsEmail, IsString, MinLength } from 'class-validator';
export class CreateUserDto {
@IsString()
@MinLength(2)
name: string;
@IsEmail()
email: string;
@IsString()
@MinLength(6)
password: string;
}
// src/users/users.service.ts
import { Injectable } from '@nestjs/common';
import { CreateUserDto } from './dto/create-user.dto';
@Injectable()
export class UsersService {
private users = [];
create(createUserDto: CreateUserDto) {
const user = { id: Date.now(), ...createUserDto };
this.users.push(user);
return user;
}
findAll() {
return this.users;
}
findOne(id: number) {
return this.users.find(user => user.id === id);
}
remove(id: number) {
this.users = this.users.filter(user => user.id !== id);
return { deleted: true };
}
}
// src/users/users.controller.ts
import { Controller, Get, Post, Body, Param, Delete } from '@nestjs/common';
import { UsersService } from './users.service';
import { CreateUserDto } from './dto/create-user.dto';
@Controller('users')
export class UsersController {
constructor(private readonly usersService: UsersService) {}
@Post()
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Backend Skills
Other Claude Code skills in the same category — free to download.
Express Setup
Scaffold Express.js app with best practices
Fastify Setup
Scaffold Fastify app with plugins
Middleware Chain
Create and organize middleware chain
Queue Worker
Set up job queue with Bull/BullMQ
File Upload Handler
Create file upload handling with validation
Email Service
Set up transactional email service
WebSocket Setup
Implement WebSocket server with rooms
Cron Job Setup
Set up scheduled cron jobs
Want a Backend skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.