Main Site โ†—

nestjs

by pluginagentmarketplace10GitHub

Build enterprise-grade Node.js applications with NestJS framework, TypeScript, dependency injection, and modular architecture

Unlock Deep Analysis

Use AI to visualize the workflow and generate a realistic output preview for this skill.

Powered by Fastest LLM

Development
nestjsnodejstypescriptbackendapi
Compatible Agents
Claude Code
Claude Code
~/.claude/skills/
Codex CLI
Codex CLI
~/.codex/skills/
Gemini CLI
Gemini CLI
~/.gemini/skills/
O
OpenCode
~/.opencode/skills/
O
OpenClaw
~/.openclaw/skills/
GitHub Copilot
GitHub Copilot
~/.copilot/skills/
Cursor
Cursor
~/.cursor/skills/
W
Windsurf
~/.codeium/windsurf/skills/
C
Cline
~/.cline/skills/
R
Roo Code
~/.roo/skills/
K
Kiro
~/.kiro/skills/
J
Junie
~/.junie/skills/
A
Augment Code
~/.augment/skills/
W
Warp
~/.warp/skills/
G
Goose
~/.config/goose/skills/
SKILL.md

Dependency Injection

  • Provider not available โ€” must be in providers array AND exports if 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] not providers: [UserService]
  • exports makes providers available to importers โ€” without it, provider stays private
  • Global modules need @Global() decorator โ€” only for truly shared (config, logger)
  • forRoot() vs forRootAsync() โ€” async for when config depends on other providers

Validation

  • ValidationPipe needs class-validator decorators โ€” plain classes won't validate
  • Enable transform: true for auto-transformation โ€” string "1" to number 1
  • whitelist: true strips unknown properties โ€” forbidNonWhitelisted: true to 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() not return โ€” must throw for filter to catch
  • Custom exceptions extend HttpException โ€” or implement ExceptionFilter
  • Unhandled exceptions become 500 โ€” wrap external calls in try/catch
  • Built-in exceptions: BadRequestException, NotFoundException, etc. โ€” use these, not generic HttpException

Testing

  • createTestingModule doesn't auto-mock โ€” provide mocks explicitly in providers
  • Override with .overrideProvider(X).useValue(mock) โ€” before .compile()
  • E2E tests need app.init() โ€” and app.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 โ€” use ParseIntPipe for 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 await on async service methods โ€” returns Promise, not value

Source: https://github.com/pluginagentmarketplace/custom-plugin-nodejs#skills~nestjs

Content curated from original sources, copyright belongs to authors

Grade B
-AI Score
Best Practices
Checking...
Try this Skill

User Rating

USER RATING

0UP
0DOWN
Loading files...

WORKS WITH

Claude Code
Claude
Codex CLI
Codex
Gemini CLI
Gemini
O
OpenCode
O
OpenClaw
GitHub Copilot
Copilot
Cursor
Cursor
W
Windsurf
C
Cline
R
Roo
K
Kiro
J
Junie
A
Augment
W
Warp
G
Goose