技能 nestjs-expert
📦

nestjs-expert

安全

构建企业级 NestJS 应用

NestJS 开发者面临复杂的架构挑战,包括依赖注入、模块组织和认证设置。本技能提供 NestJS 模式、测试策略和常见问题解决的专业指导。

支援: Claude Codex Code(CC)
⚠️ 66
1

下載技能 ZIP

2

在 Claude 中上傳

前往 設定 → 功能 → 技能 → 上傳技能

3

開啟並開始使用

測試它

正在使用「nestjs-expert」。 如何修复「无法解析 UserService 依赖」错误?

預期結果:

此错误通常意味着模块中缺少一个提供者。检查:1) 依赖是否在模块的 providers 数组中?2) 如果跨模块使用,是否已导出?3) 检查提供者名称中的拼写错误。如果两个服务之间存在循环依赖,请使用 forwardRef()。

正在使用「nestjs-expert」。 使用 Passport 设置 JWT 认证

預期結果:

1) 安装 @nestjs/passport、@nestjs/jwt、passport、passport-jwt。2) 创建扩展 PassportStrategy(Strategy) 的 JwtStrategy。3) 在 forRoot() 中配置带密钥的 JwtModule。4) 使用 JwtAuthGuard 创建 AuthGuard。5) 在受保护路由上应用 @UseGuards(AuthGuard)。

安全審計

安全
v1 • 2/24/2026

All static findings are false positives. The skill provides documentation and CLI command references for Nest.js development - standard patterns for a framework expert skill. No malicious code execution, credential exfiltration, or cryptographic vulnerabilities exist. External commands are documented CLI tools, network URLs are official documentation links, and environment variable references are legitimate configuration guidance.

1
已掃描檔案
558
分析行數
5
發現項
1
審計總數

嚴重問題 (1)

False Positive: Dangerous Combination Heuristic
Static scanner flagged 'Code execution + Network + Credential access' as dangerous. This is a false positive. The skill documents standard development workflows: CLI commands (nest generate), documentation URLs, and JWT_SECRET environment variable configuration - all legitimate Nest.js development patterns.

高風險問題 (2)

False Positive: Weak Cryptographic Algorithm
Scanner flagged lines as 'weak cryptographic algorithm'. Upon review: lines contain YAML frontmatter, forwardRef() for DI, and TypeORM decorators. No cryptographic code exists.
False Positive: Sensitive Data Exposure
Scanner flagged JWT_SECRET environment variable as sensitive exposure. This is legitimate authentication configuration guidance - standard practice for secure JWT implementation.
低風險問題 (2)
False Positive: External Commands
Scanner flagged shell backticks as 'external_commands'. These are documentation showing CLI commands (nest generate, npm run build, grep, find) - not actual code execution. This is standard developer documentation.
False Positive: Network Access (Hardcoded URLs)
Scanner flagged hardcoded URLs. These are official documentation links to Nest.js, Jest, TypeORM, and Passport.js - legitimate reference material.
審計者: claude

品質評分

38
架構
100
可維護性
87
內容
50
社群
61
安全
87
規範符合性

你能建構什麼

修复 NestJS 依赖注入错误

通过识别缺失的提供者、错误的模块导出或循环依赖来解析「无法解析依赖」错误。

设置 JWT 认证

使用 JWT 配置 Passport.js 策略、正确的守卫实现和令牌验证。

编写全面测试

使用 mocks 创建单元测试、使用测试数据库创建集成测试、使用 Supertest 创建端到端测试。

試試這些提示

修复循环依赖
我在 NestJS 应用程序中的 UserService 和 AuthService 之间遇到「检测到循环依赖」错误。请帮助我使用 forwardRef() 或重构架构来解决此问题。
设置 JWT 认证
我需要使用 Passport.js 在我的 NestJS 应用中实现 JWT 认证。向我展示如何配置 JwtStrategy、JwtModule 和 AuthGuard。
编写单元测试
帮助我使用 Jest 为 UserService 编写单元测试。它依赖于 UserRepository 和 JwtService。向我展示正确的 mocking。
配置 TypeORM 实体
我有一个与 Posts 和 Comments 关联的 User 实体。向我展示如何在 NestJS 中使用 TypeORM 配置 OneToMany 和 ManyToOne 关系。

最佳實務

  • 使用依赖注入保持服务松散耦合和可测试
  • 遵循模块化架构:每个域实体一个功能模块
  • 始终使用 class-validator 和 class-transformer 管道验证 DTO

避免

  • 避免直接将模块导入控制器 - 使用服务注入
  • 不要跳过验证管道 - 始终验证传入的请求数据
  • 避免模块之间紧密耦合 - 使用导出和接口

常見問題

什么是 NestJS?
NestJS 是一个用于构建高效、可扩展的服务器端应用程序的 Node.js 框架。它使用 TypeScript 并结合了 OOP、FP 和 FRP 的元素。
如何修复 NestJS 中的循环依赖?
在循环依赖的两侧使用 forwardRef(),或者将共享逻辑重构到第三个模块中。
如何测试 NestJS 服务?
使用 @nestjs/testing 创建 Test.createTestingModule()。使用 useValue 或 useClass mock 依赖项,然后编译并测试服务。
守卫和拦截器有什么区别?
守卫决定路由是否可以被访问(授权)。拦截器在方法执行之前或之后转换请求/响应或添加额外逻辑。
如何配置 NestJS 与 TypeORM?
使用 @nestjs/typeorm 包。在 AppModule 中导入 TypeOrmModule.forRoot(),在功能模块中使用实体数组导入 TypeOrmModule.forFeature()。
这个技能可以编写完整的应用程序吗?
本技能提供专业指导、代码模式和问题排查。它帮助您理解和实现 NestJS 解决方案,而不是生成完整的应用程序。

開發者詳情

檔案結構

📄 SKILL.md