← 返回
未分类 中文

Nest.JS

Build production-grade NestJS applications with correct module architecture, dependency injection, decorators, guards, pipes, interceptors, middleware, micro...
使用正确的模块架构、依赖注入、装饰器、守卫、管道、拦截器、中间件及微服务等构建生产级 NestJS 应用
encryptshawn encryptshawn 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 397
下载
💾 0
安装
1
版本
#latest

概述

Quick Reference

TopicFile
-------------
Module system, circular deps, dynamic modulesmodules.md
DI, providers, injection scopes, custom providersdependency-injection.md
Controllers, routing, request lifecyclecontrollers.md
Guards, pipes, interceptors, middleware, filterslifecycle.md
DTOs, validation, transformationvalidation.md
Database integration (TypeORM, Prisma, Mongoose)database.md
Testing: unit, integration, e2etesting.md
Microservices, queues, events, WebSocketsmicroservices.md
Config, environment, secrets managementconfig.md
Performance, caching, serializationperformance.md

NestJS vs Plain Node.js — Key Differences

NestJS builds on Node.js/Express (or Fastify) but introduces an opinionated architecture. The main things that catch people:

  • Everything is a class with decorators@Module, @Controller, @Injectable are not optional annotations, they drive the DI container and module graph.
  • Module boundaries matter — a provider is NOT globally available unless explicitly exported and imported. This is the #1 source of "Nest can't resolve dependency" errors.
  • Request lifecycle is layered — Middleware → Guards → Interceptors (before) → Pipes → Handler → Interceptors (after) → Exception Filters. Order matters and each layer has a distinct job.
  • TypeScript is assumed — decorators, metadata reflection (reflect-metadata), and emitDecoratorMetadata are load-bearing. Misconfigured tsconfig.json breaks DI silently.

Critical Traps

  • @Injectable() missing — class won't be in DI container, cryptic "resolve dependency" error
  • Provider not in module's providers array — same error, different cause
  • Provider not exportsed — importing module can't see it, even though the module is imported
  • Circular module dependency — use forwardRef(() => ModuleClass) on BOTH sides
  • Circular provider injection — use forwardRef(() => ServiceClass) + @Inject(forwardRef(...))
  • @Body() empty — missing Content-Type: application/json header or body-parser not configured
  • Validation not firing — forgot app.useGlobalPipes(new ValidationPipe()) or missing class-transformer
  • Guard returning false silently → 403 — no error message by default, must throw specific exception
  • @Res() used → Nest loses response control — use @Res({ passthrough: true }) or avoid @Res()
  • Exception filter not catching — filter bound to wrong scope (method vs controller vs global)
  • onModuleInit / onModuleDestroy — lifecycle hooks only fire if class is @Injectable() AND in providers
  • ConfigService.get() returns undefined — env var not in .env or ConfigModule not imported in that module
  • Fastify adapter — Express middleware won't work, must use Fastify equivalents

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-07 06:57 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

dev-programming

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 681 📥 329,285
office-efficiency

Email MCP Helper

encryptshawn
访问和管理多个IMAP/SMTP邮箱账户,配备完整生命周期工具,支持读取、搜索、发送、回复、转发、文件夹和标签管理...
★ 0 📥 642
dev-programming

Mcporter

steipete
使用 mcporter CLI 直接列出、配置、认证及调用 MCP 服务器/工具(支持 HTTP 或 stdio),涵盖临时服务器、配置编辑及 CLI/类型生成功能。
★ 196 📥 67,936