nest
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseNestJS is a progressive Node.js framework for building efficient and scalable server-side applications. It uses TypeScript by default, supports both Express and Fastify, and provides an out-of-the-box application architecture inspired by Angular. NestJS combines elements of OOP, FP, and FRP, making it ideal for building enterprise-grade applications.
The skill is based on NestJS documentation, generated at 2026-02-01.
NestJS 是一款渐进式 Node.js 框架,用于构建高效、可扩展的服务端应用。它默认使用 TypeScript,同时支持 Express 和 Fastify,并提供了受 Angular 启发的开箱即用的应用架构。NestJS 融合了 OOP(面向对象编程)、FP(函数式编程)和 FRP(函数响应式编程)的特性,非常适合构建企业级应用。
本技能基于 NestJS 文档生成,生成时间为 2026-02-01。
CLI
CLI
| Topic | Description | Reference |
|---|---|---|
| CLI Overview | Scaffolding, building, and running applications | cli-overview |
| Monorepo & Libraries | Workspaces, apps, shared libraries | cli-monorepo |
| 主题 | 描述 | 参考链接 |
|---|---|---|
| CLI 概述 | 脚手架搭建、构建及运行应用 | cli-overview |
| 单仓库与库 | 工作区、应用、共享库 | cli-monorepo |
Core References
核心参考
| Topic | Description | Reference |
|---|---|---|
| Controllers | Route handlers, HTTP methods, request/response handling | core-controllers |
| Modules | Application structure, feature modules, shared modules, dynamic modules | core-modules |
| Providers | Services, dependency injection, custom providers | core-providers |
| Dependency Injection | DI fundamentals, custom providers, scopes | core-dependency-injection |
| Middleware | Request/response middleware, functional middleware | core-middleware |
| 主题 | 描述 | 参考链接 |
|---|---|---|
| 控制器 | 路由处理器、HTTP 方法、请求/响应处理 | core-controllers |
| 模块 | 应用结构、功能模块、共享模块、动态模块 | core-modules |
| 提供者 | 服务、依赖注入、自定义提供者 | core-providers |
| 依赖注入 | DI 基础、自定义提供者、作用域 | core-dependency-injection |
| 中间件 | 请求/响应中间件、函数式中间件 | core-middleware |
Fundamentals
基础特性
| Topic | Description | Reference |
|---|---|---|
| Pipes | Data transformation and validation pipes | fundamentals-pipes |
| Guards | Authorization guards, role-based access control | fundamentals-guards |
| Interceptors | Aspect-oriented programming, response transformation | fundamentals-interceptors |
| Exception Filters | Error handling, custom exception filters | fundamentals-exception-filters |
| Custom Decorators | Creating custom parameter decorators | fundamentals-custom-decorators |
| Dynamic Modules | Configurable modules, module configuration | fundamentals-dynamic-modules |
| Execution Context | Accessing request context, metadata reflection | fundamentals-execution-context |
| Provider Scopes | Singleton, request-scoped, transient providers | fundamentals-provider-scopes |
| Lifecycle Events | Application and provider lifecycle hooks | fundamentals-lifecycle-events |
| Lazy Loading | Loading modules on-demand for serverless | fundamentals-lazy-loading |
| Circular Dependency | Resolving circular dependencies with forwardRef | fundamentals-circular-dependency |
| Module Reference | Accessing providers dynamically with ModuleRef | fundamentals-module-reference |
| Testing | Unit testing and e2e testing with @nestjs/testing | fundamentals-testing |
| 主题 | 描述 | 参考链接 |
|---|---|---|
| 管道 | 数据转换与验证管道 | fundamentals-pipes |
| 守卫 | 授权守卫、基于角色的访问控制 | fundamentals-guards |
| 拦截器 | 面向切面编程、响应转换 | fundamentals-interceptors |
| 异常过滤器 | 错误处理、自定义异常过滤器 | fundamentals-exception-filters |
| 自定义装饰器 | 创建自定义参数装饰器 | fundamentals-custom-decorators |
| 动态模块 | 可配置模块、模块配置 | fundamentals-dynamic-modules |
| 执行上下文 | 访问请求上下文、元数据反射 | fundamentals-execution-context |
| 提供者作用域 | 单例、请求作用域、临时提供者 | fundamentals-provider-scopes |
| 生命周期事件 | 应用与提供者生命周期钩子 | fundamentals-lifecycle-events |
| 懒加载 | 为无服务器架构按需加载模块 | fundamentals-lazy-loading |
| 循环依赖 | 使用 forwardRef 解决循环依赖 | fundamentals-circular-dependency |
| 模块引用 | 使用 ModuleRef 动态访问提供者 | fundamentals-module-reference |
| 测试 | 使用 @nestjs/testing 进行单元测试与端到端测试 | fundamentals-testing |
Techniques
技术实践
| Topic | Description | Reference |
|---|---|---|
| Validation | ValidationPipe, class-validator, DTO validation | techniques-validation |
| Configuration | Environment variables, ConfigModule, configuration management | techniques-configuration |
| Database | TypeORM, Prisma, MongoDB integration | techniques-database |
| Caching | Cache manager, Redis integration, auto-caching | techniques-caching |
| Logging | Built-in logger, custom loggers, JSON logging | techniques-logging |
| File Upload | File upload handling with multer, validation | techniques-file-upload |
| Versioning | URI, header, and media type API versioning | techniques-versioning |
| Serialization | Response serialization with class-transformer | techniques-serialization |
| Queues | Background job processing with BullMQ | techniques-queues |
| Task Scheduling | Cron jobs, intervals, and timeouts | techniques-task-scheduling |
| Events | Event-driven architecture with EventEmitter | techniques-events |
| HTTP Module | Making HTTP requests with Axios | techniques-http-module |
| Fastify | Using Fastify for better performance | techniques-fastify |
| Sessions & Cookies | HTTP sessions and cookies for stateful apps | techniques-sessions-cookies |
| Streaming & SSE | Compression, file streaming, Server-Sent Events | techniques-compression-streaming-sse |
| MVC & Serve Static | Template rendering (Handlebars) and SPA static serving | techniques-mvc-serve-static |
| 主题 | 描述 | 参考链接 |
|---|---|---|
| 验证 | ValidationPipe、class-validator、DTO 验证 | techniques-validation |
| 配置 | 环境变量、ConfigModule、配置管理 | techniques-configuration |
| 数据库 | TypeORM、Prisma、MongoDB 集成 | techniques-database |
| 缓存 | 缓存管理器、Redis 集成、自动缓存 | techniques-caching |
| 日志 | 内置日志器、自定义日志器、JSON 日志 | techniques-logging |
| 文件上传 | 使用 multer 处理文件上传、验证 | techniques-file-upload |
| 版本控制 | URI、请求头、媒体类型 API 版本控制 | techniques-versioning |
| 序列化 | 使用 class-transformer 进行响应序列化 | techniques-serialization |
| 队列 | 使用 BullMQ 处理后台任务 | techniques-queues |
| 任务调度 | Cron 任务、间隔任务与超时任务 | techniques-task-scheduling |
| 事件 | 基于 EventEmitter 的事件驱动架构 | techniques-events |
| HTTP 模块 | 使用 Axios 发起 HTTP 请求 | techniques-http-module |
| Fastify | 使用 Fastify 提升性能 | techniques-fastify |
| 会话与 Cookie | 为有状态应用提供 HTTP 会话与 Cookie | techniques-sessions-cookies |
| 流与 SSE | 压缩、文件流、服务器发送事件 | techniques-compression-streaming-sse |
| MVC 与静态资源服务 | 模板渲染(Handlebars)与 SPA 静态资源服务 | techniques-mvc-serve-static |
Security
安全
| Topic | Description | Reference |
|---|---|---|
| Authentication | Passport integration, JWT authentication | recipes-authentication |
| Authorization | RBAC, claims-based, CASL integration | security-authorization |
| CORS & Rate Limiting | CORS, Helmet, ThrottlerModule | security-cors-helmet-rate-limiting |
| Encryption & Hashing | bcrypt, argon2, password hashing | security-encryption-hashing |
| 主题 | 描述 | 参考链接 |
|---|---|---|
| 身份认证 | Passport 集成、JWT 身份认证 | recipes-authentication |
| 授权 | RBAC、基于声明的授权、CASL 集成 | security-authorization |
| CORS 与速率限制 | CORS、Helmet、ThrottlerModule | security-cors-helmet-rate-limiting |
| 加密与哈希 | bcrypt、argon2、密码哈希 | security-encryption-hashing |
OpenAPI
OpenAPI
| Topic | Description | Reference |
|---|---|---|
| Swagger | OpenAPI documentation generation | openapi-swagger |
| 主题 | 描述 | 参考链接 |
|---|---|---|
| Swagger | OpenAPI 文档生成 | openapi-swagger |
WebSockets
WebSockets
| Topic | Description | Reference |
|---|---|---|
| Gateways | Real-time communication with Socket.IO/ws | websockets-gateways |
| Guards & Exception Filters | WsException, BaseWsExceptionFilter, interceptors, pipes | websockets-advanced |
| 主题 | 描述 | 参考链接 |
|---|---|---|
| 网关 | 使用 Socket.IO/ws 实现实时通信 | websockets-gateways |
| 守卫与异常过滤器 | WsException、BaseWsExceptionFilter、拦截器、管道 | websockets-advanced |
Microservices
微服务
| Topic | Description | Reference |
|---|---|---|
| Overview | Transport layers, message patterns, events | microservices-overview |
| gRPC | Protocol Buffers, streaming, metadata, reflection | microservices-grpc |
| Transports | Redis, Kafka, NATS, RabbitMQ configuration | microservices-transports |
| 主题 | 描述 | 参考链接 |
|---|---|---|
| 概述 | 传输层、消息模式、事件 | microservices-overview |
| gRPC | Protocol Buffers、流、元数据、反射 | microservices-grpc |
| 传输层 | Redis、Kafka、NATS、RabbitMQ 配置 | microservices-transports |
GraphQL
GraphQL
| Topic | Description | Reference |
|---|---|---|
| Overview | Code-first and schema-first approaches | graphql-overview |
| Resolvers & Mutations | Queries, mutations, field resolvers | graphql-resolvers-mutations |
| Subscriptions | Real-time subscriptions with PubSub | graphql-subscriptions |
| Scalars, Unions & Enums | Interfaces, scalars, union types, enums | graphql-scalars-unions-enums |
| 主题 | 描述 | 参考链接 |
|---|---|---|
| 概述 | 代码优先与架构优先方案 | graphql-overview |
| 解析器与变更 | 查询、变更、字段解析器 | graphql-resolvers-mutations |
| 订阅 | 使用 PubSub 实现实时订阅 | graphql-subscriptions |
| 标量、联合类型与枚举 | 接口、标量、联合类型、枚举 | graphql-scalars-unions-enums |
Recipes
实践方案
| Topic | Description | Reference |
|---|---|---|
| CRUD Generator | Nest CLI resource generator | recipes-crud-generator |
| Documentation | OpenAPI/Swagger integration | recipes-documentation |
| TypeORM | TypeORM integration and usage | recipes-typeorm |
| Prisma | Prisma ORM integration | recipes-prisma |
| Mongoose | MongoDB with Mongoose ODM | recipes-mongoose |
| CQRS | Command Query Responsibility Segregation | recipes-cqrs |
| Terminus | Health checks and readiness/liveness probes | recipes-terminus |
| 主题 | 描述 | 参考链接 |
|---|---|---|
| CRUD 生成器 | Nest CLI 资源生成器 | recipes-crud-generator |
| 文档 | OpenAPI/Swagger 集成 | recipes-documentation |
| TypeORM | TypeORM 集成与使用 | recipes-typeorm |
| Prisma | Prisma ORM 集成 | recipes-prisma |
| Mongoose | 使用 Mongoose ODM 操作 MongoDB | recipes-mongoose |
| CQRS | 命令查询职责分离 | recipes-cqrs |
| Terminus | 健康检查与就绪/存活探针 | recipes-terminus |
FAQ
常见问题
| Topic | Description | Reference |
|---|---|---|
| Raw Body & Hybrid | Webhook signature verification, HTTP + microservices | faq-raw-body-hybrid |
| 主题 | 描述 | 参考链接 |
|---|---|---|
| 原始请求体与混合架构 | Webhook 签名验证、HTTP + 微服务 | faq-raw-body-hybrid |
Best Practices
最佳实践
| Topic | Description | Reference |
|---|---|---|
| Request Lifecycle | Understanding execution order and flow | best-practices-request-lifecycle |
| 主题 | 描述 | 参考链接 |
|---|---|---|
| 请求生命周期 | 理解执行顺序与流程 | best-practices-request-lifecycle |