nestjs
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWhen to use this skill
何时使用此技能
Use this skill whenever the user wants to:
- Build or refactor a NestJS application
- Implement controllers, providers, and modules
- Apply middleware, pipes, guards, or interceptors
- Configure DI scopes, dynamic modules, or lifecycle hooks
- Add validation, serialization, caching, logging, or queues
- Integrate GraphQL, WebSockets, or microservices
- Document APIs with OpenAPI/Swagger
- Implement authentication/authorization or security hardening
- Write unit or e2e tests for NestJS
当用户有以下需求时,即可使用此技能:
- 构建或重构NestJS应用
- 实现控制器、提供者和模块
- 应用中间件、管道、守卫或拦截器
- 配置DI作用域、动态模块或生命周期钩子
- 添加验证、序列化、缓存、日志或队列功能
- 集成GraphQL、WebSocket或微服务
- 使用OpenAPI/Swagger编写API文档
- 实现身份验证/授权或安全加固
- 为NestJS编写单元测试或端到端测试
How to use this skill
如何使用此技能
-
Identify the topic from the user's request and find the corresponding example file in the mapping below
-
Load the appropriate example file from thedirectory
examples/ -
Follow the specific instructions in that example file for syntax, structure, and best practicesImportant Notes:
- All examples follow NestJS official documentation structure
- Examples include both JavaScript and TypeScript versions where applicable
- Each example file includes key concepts, code examples, and official documentation links
- Always check the example file for best practices and common patterns
-
Use templates from thedirectory to speed up common scaffolding
templates/
-
识别主题:从用户的请求中确定主题,然后在下方的映射表中找到对应的示例文件
-
加载对应的示例文件:从目录中加载合适的示例文件
examples/ -
遵循示例文件中的具体说明:按照文件中的语法、结构和最佳实践操作重要提示:
- 所有示例均遵循NestJS官方文档结构
- 适用的情况下,示例包含JavaScript和TypeScript两种版本
- 每个示例文件都包含核心概念、代码示例和官方文档链接
- 请务必查看示例文件中的最佳实践和通用模式
-
使用模板:利用目录中的模板加速常见代码脚手架的搭建
templates/
Doc mapping (one-to-one with https://docs.nestjs.com/)
文档映射(与https://docs.nestjs.com/ 一一对应)
Overview (概览)
- → https://docs.nestjs.com/
examples/overview/introduction.md - → https://docs.nestjs.com/first-steps
examples/fundamentals/first-steps.md - → https://docs.nestjs.com/controllers
examples/fundamentals/controllers.md - → https://docs.nestjs.com/providers
examples/fundamentals/providers.md - → https://docs.nestjs.com/modules
examples/fundamentals/modules.md - → https://docs.nestjs.com/middleware
examples/fundamentals/middleware.md - → https://docs.nestjs.com/exception-filters
examples/fundamentals/exception-filters.md - → https://docs.nestjs.com/pipes
examples/fundamentals/pipes.md - → https://docs.nestjs.com/guards
examples/fundamentals/guards.md - → https://docs.nestjs.com/interceptors
examples/fundamentals/interceptors.md - → https://docs.nestjs.com/custom-decorators
examples/overview/custom-decorators.md
Fundamentals (基础)
- → https://docs.nestjs.com/fundamentals/custom-providers
examples/fundamentals/custom-providers.md - → https://docs.nestjs.com/fundamentals/async-providers
examples/fundamentals/async-providers.md - → https://docs.nestjs.com/fundamentals/dynamic-modules
examples/fundamentals/dynamic-modules.md - → https://docs.nestjs.com/fundamentals/module-ref
examples/fundamentals/module-ref.md - → https://docs.nestjs.com/fundamentals/execution-context
examples/fundamentals/execution-context.md - → https://docs.nestjs.com/fundamentals/lifecycle-events
examples/fundamentals/lifecycle-events.md - → https://docs.nestjs.com/fundamentals/injection-scopes
examples/fundamentals/injection-scopes.md - → https://docs.nestjs.com/fundamentals/request-scoped
examples/fundamentals/request-scoped.md - → https://docs.nestjs.com/fundamentals/circular-dependency
examples/fundamentals/circular-dependency.md
Techniques (技巧)
- → https://docs.nestjs.com/techniques/configuration
examples/techniques/configuration.md - → https://docs.nestjs.com/techniques/validation
examples/techniques/validation.md - → https://docs.nestjs.com/techniques/serialization
examples/techniques/serialization.md - → https://docs.nestjs.com/techniques/caching
examples/techniques/caching.md - → https://docs.nestjs.com/techniques/logger
examples/techniques/logger.md - → https://docs.nestjs.com/techniques/events
examples/techniques/events.md - → https://docs.nestjs.com/techniques/task-scheduling
examples/techniques/task-scheduling.md - → https://docs.nestjs.com/techniques/queues
examples/techniques/queues.md - → https://docs.nestjs.com/techniques/file-upload
examples/techniques/file-upload.md - → https://docs.nestjs.com/techniques/streaming-files
examples/techniques/streaming-files.md - → https://docs.nestjs.com/techniques/database
examples/techniques/database.md - → https://docs.nestjs.com/techniques/mongodb
examples/techniques/mongodb.md - → https://docs.nestjs.com/techniques/mongoose
examples/techniques/mongoose.md - → https://docs.nestjs.com/techniques/sequelize
examples/techniques/sequelize.md - → https://docs.nestjs.com/recipes/prisma
examples/techniques/prisma.md
Security (安全)
- → https://docs.nestjs.com/security/authentication
examples/security/authentication.md - → https://docs.nestjs.com/security/authorization
examples/security/authorization.md - → https://docs.nestjs.com/security/helmet
examples/security/helmet.md - → https://docs.nestjs.com/security/cors
examples/security/cors.md - → https://docs.nestjs.com/security/rate-limiting
examples/security/rate-limiting.md
GraphQL
- → https://docs.nestjs.com/graphql/quick-start
examples/graphql/quick-start.md - → https://docs.nestjs.com/graphql/resolvers
examples/graphql/resolvers.md - → https://docs.nestjs.com/graphql/scalars
examples/graphql/scalars.md - → https://docs.nestjs.com/graphql/interfaces
examples/graphql/interfaces.md - → https://docs.nestjs.com/graphql/unions
examples/graphql/unions.md - → https://docs.nestjs.com/graphql/directives
examples/graphql/directives.md - → https://docs.nestjs.com/graphql/plugins
examples/graphql/plugins.md - → https://docs.nestjs.com/graphql/subscriptions
examples/graphql/subscriptions.md - → https://docs.nestjs.com/graphql/federation
examples/graphql/federation.md - → https://docs.nestjs.com/graphql/migration
examples/graphql/migration.md
WebSockets
- → https://docs.nestjs.com/websockets/gateways
examples/websockets/gateways.md - → https://docs.nestjs.com/websockets/exception-filters
examples/websockets/exception-filters.md - → https://docs.nestjs.com/websockets/guards
examples/websockets/guards.md - → https://docs.nestjs.com/websockets/interceptors
examples/websockets/interceptors.md - → https://docs.nestjs.com/websockets/adapters
examples/websockets/adapters.md
Microservices
- → https://docs.nestjs.com/microservices/basics
examples/microservices/basics.md - → https://docs.nestjs.com/microservices/redis
examples/microservices/redis.md - → https://docs.nestjs.com/microservices/mqtt
examples/microservices/mqtt.md - → https://docs.nestjs.com/microservices/nats
examples/microservices/nats.md - → https://docs.nestjs.com/microservices/kafka
examples/microservices/kafka.md - → https://docs.nestjs.com/microservices/grpc
examples/microservices/grpc.md - → https://docs.nestjs.com/microservices/rabbitmq
examples/microservices/rabbitmq.md - → https://docs.nestjs.com/microservices/custom-transport
examples/microservices/custom-transport.md - → https://docs.nestjs.com/microservices/hybrid-application
examples/microservices/hybrid-application.md
OpenAPI (Swagger)
- → https://docs.nestjs.com/openapi/introduction
examples/openapi/introduction.md - → https://docs.nestjs.com/openapi/operations
examples/openapi/operations.md - → https://docs.nestjs.com/openapi/types-and-parameters
examples/openapi/types-and-parameters.md - → https://docs.nestjs.com/openapi/security
examples/openapi/security.md - → https://docs.nestjs.com/openapi/mapped-types
examples/openapi/mapped-types.md
CLI & Testing & Recipes
- → https://docs.nestjs.com/cli/overview
examples/cli/overview.md - → https://docs.nestjs.com/fundamentals/testing
examples/testing/unit-testing.md - → https://docs.nestjs.com/fundamentals/testing
examples/testing/e2e-testing.md - → https://docs.nestjs.com/recipes/cqrs
examples/recipes/cqrs.md - → https://docs.nestjs.com/recipes/mikroorm
examples/recipes/mikroorm.md - → https://docs.nestjs.com/recipes/terminus
examples/recipes/terminus.md - → https://docs.nestjs.com/faq
examples/faq.md
概览
- → https://docs.nestjs.com/
examples/overview/introduction.md - → https://docs.nestjs.com/first-steps
examples/fundamentals/first-steps.md - → https://docs.nestjs.com/controllers
examples/fundamentals/controllers.md - → https://docs.nestjs.com/providers
examples/fundamentals/providers.md - → https://docs.nestjs.com/modules
examples/fundamentals/modules.md - → https://docs.nestjs.com/middleware
examples/fundamentals/middleware.md - → https://docs.nestjs.com/exception-filters
examples/fundamentals/exception-filters.md - → https://docs.nestjs.com/pipes
examples/fundamentals/pipes.md - → https://docs.nestjs.com/guards
examples/fundamentals/guards.md - → https://docs.nestjs.com/interceptors
examples/fundamentals/interceptors.md - → https://docs.nestjs.com/custom-decorators
examples/overview/custom-decorators.md
基础
- → https://docs.nestjs.com/fundamentals/custom-providers
examples/fundamentals/custom-providers.md - → https://docs.nestjs.com/fundamentals/async-providers
examples/fundamentals/async-providers.md - → https://docs.nestjs.com/fundamentals/dynamic-modules
examples/fundamentals/dynamic-modules.md - → https://docs.nestjs.com/fundamentals/module-ref
examples/fundamentals/module-ref.md - → https://docs.nestjs.com/fundamentals/execution-context
examples/fundamentals/execution-context.md - → https://docs.nestjs.com/fundamentals/lifecycle-events
examples/fundamentals/lifecycle-events.md - → https://docs.nestjs.com/fundamentals/injection-scopes
examples/fundamentals/injection-scopes.md - → https://docs.nestjs.com/fundamentals/request-scoped
examples/fundamentals/request-scoped.md - → https://docs.nestjs.com/fundamentals/circular-dependency
examples/fundamentals/circular-dependency.md
技巧
- → https://docs.nestjs.com/techniques/configuration
examples/techniques/configuration.md - → https://docs.nestjs.com/techniques/validation
examples/techniques/validation.md - → https://docs.nestjs.com/techniques/serialization
examples/techniques/serialization.md - → https://docs.nestjs.com/techniques/caching
examples/techniques/caching.md - → https://docs.nestjs.com/techniques/logger
examples/techniques/logger.md - → https://docs.nestjs.com/techniques/events
examples/techniques/events.md - → https://docs.nestjs.com/techniques/task-scheduling
examples/techniques/task-scheduling.md - → https://docs.nestjs.com/techniques/queues
examples/techniques/queues.md - → https://docs.nestjs.com/techniques/file-upload
examples/techniques/file-upload.md - → https://docs.nestjs.com/techniques/streaming-files
examples/techniques/streaming-files.md - → https://docs.nestjs.com/techniques/database
examples/techniques/database.md - → https://docs.nestjs.com/techniques/mongodb
examples/techniques/mongodb.md - → https://docs.nestjs.com/techniques/mongoose
examples/techniques/mongoose.md - → https://docs.nestjs.com/techniques/sequelize
examples/techniques/sequelize.md - → https://docs.nestjs.com/recipes/prisma
examples/techniques/prisma.md
安全
- → https://docs.nestjs.com/security/authentication
examples/security/authentication.md - → https://docs.nestjs.com/security/authorization
examples/security/authorization.md - → https://docs.nestjs.com/security/helmet
examples/security/helmet.md - → https://docs.nestjs.com/security/cors
examples/security/cors.md - → https://docs.nestjs.com/security/rate-limiting
examples/security/rate-limiting.md
GraphQL
- → https://docs.nestjs.com/graphql/quick-start
examples/graphql/quick-start.md - → https://docs.nestjs.com/graphql/resolvers
examples/graphql/resolvers.md - → https://docs.nestjs.com/graphql/scalars
examples/graphql/scalars.md - → https://docs.nestjs.com/graphql/interfaces
examples/graphql/interfaces.md - → https://docs.nestjs.com/graphql/unions
examples/graphql/unions.md - → https://docs.nestjs.com/graphql/directives
examples/graphql/directives.md - → https://docs.nestjs.com/graphql/plugins
examples/graphql/plugins.md - → https://docs.nestjs.com/graphql/subscriptions
examples/graphql/subscriptions.md - → https://docs.nestjs.com/graphql/federation
examples/graphql/federation.md - → https://docs.nestjs.com/graphql/migration
examples/graphql/migration.md
WebSocket
- → https://docs.nestjs.com/websockets/gateways
examples/websockets/gateways.md - → https://docs.nestjs.com/websockets/exception-filters
examples/websockets/exception-filters.md - → https://docs.nestjs.com/websockets/guards
examples/websockets/guards.md - → https://docs.nestjs.com/websockets/interceptors
examples/websockets/interceptors.md - → https://docs.nestjs.com/websockets/adapters
examples/websockets/adapters.md
微服务
- → https://docs.nestjs.com/microservices/basics
examples/microservices/basics.md - → https://docs.nestjs.com/microservices/redis
examples/microservices/redis.md - → https://docs.nestjs.com/microservices/mqtt
examples/microservices/mqtt.md - → https://docs.nestjs.com/microservices/nats
examples/microservices/nats.md - → https://docs.nestjs.com/microservices/kafka
examples/microservices/kafka.md - → https://docs.nestjs.com/microservices/grpc
examples/microservices/grpc.md - → https://docs.nestjs.com/microservices/rabbitmq
examples/microservices/rabbitmq.md - → https://docs.nestjs.com/microservices/custom-transport
examples/microservices/custom-transport.md - → https://docs.nestjs.com/microservices/hybrid-application
examples/microservices/hybrid-application.md
OpenAPI (Swagger)
- → https://docs.nestjs.com/openapi/introduction
examples/openapi/introduction.md - → https://docs.nestjs.com/openapi/operations
examples/openapi/operations.md - → https://docs.nestjs.com/openapi/types-and-parameters
examples/openapi/types-and-parameters.md - → https://docs.nestjs.com/openapi/security
examples/openapi/security.md - → https://docs.nestjs.com/openapi/mapped-types
examples/openapi/mapped-types.md
CLI & 测试 & 实践方案
- → https://docs.nestjs.com/cli/overview
examples/cli/overview.md - → https://docs.nestjs.com/fundamentals/testing
examples/testing/unit-testing.md - → https://docs.nestjs.com/fundamentals/testing
examples/testing/e2e-testing.md - → https://docs.nestjs.com/recipes/cqrs
examples/recipes/cqrs.md - → https://docs.nestjs.com/recipes/mikroorm
examples/recipes/mikroorm.md - → https://docs.nestjs.com/recipes/terminus
examples/recipes/terminus.md - → https://docs.nestjs.com/faq
examples/faq.md
Examples and Templates
示例与模板
This skill includes detailed examples organized to match the NestJS official documentation structure (https://docs.nestjs.com/). All examples are in the directory, organized by topic (see mapping above).
examples/To use examples:
- Identify the topic from the user's request
- Load the appropriate example file from the mapping above
- Follow the instructions, syntax, and best practices in that file
- Adapt the code examples to your specific use case
To use templates:
- Reference templates in directory for common scaffolding
templates/ - Templates include: controller, provider, module, middleware, guard, pipe, interceptor, exception filter, DTO, and project structure
- Adapt templates to your specific needs and coding style
此技能包含与NestJS官方文档结构匹配的详细示例(https://docs.nestjs.com/)。所有示例均位于`examples/`目录下,按主题分类(见上方映射表)。
使用示例:
- 从用户的请求中确定主题
- 从上方映射表中加载对应的示例文件
- 遵循文件中的说明、语法和最佳实践
- 根据具体用例调整代码示例
使用模板:
- 参考目录中的模板完成常见代码脚手架搭建
templates/ - 模板包含:控制器、提供者、模块、中间件、守卫、管道、拦截器、异常过滤器、DTO和项目结构
- 根据具体需求和编码风格调整模板
Best Practices
最佳实践
- Use dependency injection: Leverage NestJS DI container for better testability and maintainability
- Organize by modules: Group related functionality into feature modules
- Use decorators consistently: Follow NestJS decorator patterns for controllers, providers, and routes
- Validate input data: Use ValidationPipe and DTOs for request validation
- Handle errors gracefully: Implement global exception filters for consistent error handling
- Use guards for authorization: Protect routes with guards rather than inline checks
- Leverage interceptors: Use interceptors for cross-cutting concerns like logging and transformation
- Type safety: Use TypeScript for better type safety and developer experience
- Test thoroughly: Write unit tests for services and E2E tests for API endpoints
- Follow official patterns: Refer to official documentation for recommended patterns and practices
- 使用依赖注入:利用NestJS的DI容器提升可测试性和可维护性
- 按模块组织代码:将相关功能分组到特性模块中
- 一致使用装饰器:遵循NestJS控制器、提供者和路由的装饰器模式
- 验证输入数据:使用ValidationPipe和DTO进行请求验证
- 优雅处理错误:实现全局异常过滤器以保证错误处理的一致性
- 使用守卫实现授权:通过守卫保护路由,而非内联检查
- 利用拦截器:使用拦截器处理日志、转换等横切关注点
- 类型安全:使用TypeScript提升类型安全性和开发体验
- 全面测试:为服务编写单元测试,为API端点编写端到端测试
- 遵循官方模式:参考官方文档获取推荐的模式和实践
Resources
资源
- Official Documentation: https://docs.nestjs.com/
- GitHub Repository: https://github.com/nestjs/nest
- 官方文档:https://docs.nestjs.com/
- GitHub仓库:https://github.com/nestjs/nest
Keywords
关键词
NestJS, Node.js, framework, controller, provider, module, middleware, exception filter, pipe, guard, interceptor, dependency injection, GraphQL, WebSocket, microservice, OpenAPI, Swagger, testing, validation, caching, logging, TypeScript, decorator, DI, IoC, 控制器, 提供者, 模块, 中间件, 守卫, 管道, 拦截器, 依赖注入
NestJS, Node.js, 框架, 控制器, 提供者, 模块, 中间件, 异常过滤器, 管道, 守卫, 拦截器, 依赖注入, GraphQL, WebSocket, 微服务, OpenAPI, Swagger, 测试, 验证, 缓存, 日志, TypeScript, 装饰器, DI, IoC, 控制器, 提供者, 模块, 中间件, 守卫, 管道, 拦截器, 依赖注入