Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
Backendintermediate

NestJS Module

Share

Generate NestJS modules, controllers, services

Works with OpenClaude

You 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 --version to confirm NestJS CLI is installed
  • Verify tsconfig.json exists and has strict: true for type safety
  • Check that the project structure follows src/ directory convention

Steps

  1. Use nest generate module [module-name] to create the module file with @Module() decorator
  2. Use nest generate service [service-name] to create the service with @Injectable() decorator and business logic methods
  3. Use nest generate controller [controller-name] to create the controller with route handlers using @Get(), @Post(), etc. decorators
  4. Import the service into the controller constructor for dependency injection
  5. Add the controller to the controllers array and service to the providers array in the module's @Module() metadata
  6. Define DTOs (Data Transfer Objects) using classes with validation decorators from class-validator
  7. Add pipes like ValidationPipe to main.ts using app.useGlobalPipes() for automatic DTO validation
  8. Export the service from the module if other modules need to import it using the exports array 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

Quick Info

CategoryBackend
Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
backendnestjstypescript

Install command:

curl -o ~/.claude/skills/nestjs-module.md https://claude-skills-hub.vercel.app/skills/backend/nestjs-module.md

Related Backend Skills

Other Claude Code skills in the same category — free to download.

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.