NestJS
Avoid common NestJS mistakes — DI scoping, circular dependencies, validation pipes, and module organization traps.
by clawic★ 23 GitHub stars
Install NestJS in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
About this skill
Dependency Injection
- Provider not available — must be in
providersarray ANDexportsif used by other modules - Circular dependency crashes — use
forwardRef(() => Module)in both modules - Default scope is singleton — same instance across requests, careful with state
- Request-scoped provider —
@Injectable({ scope: Scope.REQUEST }), propagates to dependents
Module Organization
- Import module, not provider directly —
imports: [UserModule]notproviders: [UserService] exportsmakes providers available to importers — without it, provider stays private- Global modules need
@Global()decorator — only for truly shared (config, logger) forRoot()vsforRootAsync()— async for when config depends on other providers
Validation
ValidationPipeneedsclass-validatordecorators — plain classes won't validate- Enable
transform: truefor auto-transformation — string"1"to number1 whitelist: truestrips unknown properties —forbidNonWhitelisted: trueto error instead- Nested objects need
@ValidateNested()AND@Type(() => NestedDto)— both required
Execution Order
- Middleware → Guards → Interceptors (pre) → Pipes → Handler → Interceptors (post) → Filters
- Guards can't access transformed body — run before pipes
- Global pipes run before route pipes — but after guards
- Exception filters catch errors from entire chain — including guards and pipes
Exception Handling
throw new HttpException()notreturn— must throw for filter to catch- Custom exceptions extend
HttpException— or implementExceptionFilter - Unhandled exceptions become 500 — wrap external calls in try/catch
- Built-in exceptions:
BadRequestException,NotFoundException, etc. — use these, not generic HttpException
Testing
createTestingModuledoesn't auto-mock — provide mocks explicitly inproviders- Override with
.overrideProvider(X).useValue(mock)— before.compile() - E2E tests need
app.init()— andapp.close()in afterAll - Request-scoped providers complicate unit tests — consider making them singleton when possible
Common Mistakes
@Body()without DTO returns plain object — no validation, no transformation@Param('id')is always string — useParseIntPipefor number:@Param('id', ParseIntPipe)- Guards returning false gives 403 — throw specific exception for better error messages
- Async providers need factory —
useFactory: async () => await createConnection() - Forgetting
awaiton async service methods — returns Promise, not value
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
- _meta.json
FAQ
What does the NestJS skill do?
Avoid common NestJS mistakes — DI scoping, circular dependencies, validation pipes, and module organization traps.
How do I install the NestJS skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the NestJS skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…