技能 nestjs-expert
📦

nestjs-expert

安全

建構企業級 NestJS 應用程式

NestJS 開發人員面臨複雜的架構挑戰,包括依賴注入、模組組織和身份驗證設定。此技能提供 NestJS 模式、測試策略和常見問題解決方案的專業指導。

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

下載技能 ZIP

2

在 Claude 中上傳

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

3

開啟並開始使用

測試它

正在使用「nestjs-expert」。 如何修復 'Cannot resolve dependencies of 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 與 secret。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
內容
33
社群
61
安全
87
規範符合性

你能建構什麼

修復 NestJS 依賴注入錯誤

透過識別遺失的提供者、不正確的模組匯出或循環依賴來解決 'Cannot resolve dependencies' 錯誤。

設定 JWT 身份驗證

配置 Passport.js 策略與 JWT、適當的 guard 實作和 token 驗證。

編寫全面的測試

使用 mocks 建立單元測試、使用測試資料庫的整合測試,以及使用 Supertest 的 e2e 測試。

試試這些提示

修復循環依賴
我的 NestJS 應用程式在 UserService 和 AuthService 之間出現 'Circular dependency detected' 錯誤。請幫助我使用 forwardRef() 或重構架構來解決這個問題。
設定 JWT 身份驗證
我需要在 NestJS 應用程式中使用 Passport.js 實作 JWT 身份驗證。請展示如何配置 JwtStrategy、JwtModule 和 AuthGuard。
編寫單元測試
請幫助我使用 Jest 為我的 UserService 編寫單元測試。它依賴於 UserRepository 和 JwtService。請展示適當的 mocking 方法。
配置 TypeORM 實體
我有一個 User 實體,與 Posts 和 Comments 有關聯。請展示如何在 TypeORM 與 NestJS 中配置 OneToMany 和 ManyToOne 關聯。

最佳實務

  • 使用依賴注入來保持服務之間的鬆耦合和可測試性
  • 遵循模組化架構:每個領域實體一個功能模組
  • 始終使用 class-validator 和 class-transformer pipes 驗證 DTOs

避免

  • 避免在控制器中直接匯入模組 - 使用服務注入
  • 不要跳過驗證 pipes - 始終驗證傳入的請求資料
  • 避免模組之間的緊密耦合 - 使用 exports 和 interfaces

常見問題

什麼是 NestJS?
NestJS 是一個用於建構高效、可擴展的伺服器端應用程式的 Node.js 框架。它使用 TypeScript,並結合了 OOP、FP 和 FRP 的元素。
如何修復 NestJS 中的循環依賴?
在循環依賴的兩端使用 forwardRef(),或重構以將共享邏輯提取到第三個模組中。
如何測試 NestJS 服務?
使用 @nestjs/testing 建立 Test.createTestingModule()。使用 useValue 或 useClass mocking 依賴項,然後編譯並測試服務。
guards 和 interceptors 之間有什麼區別?
Guards 決定是否可以存取路由(授權)。Interceptors 轉換請求/回應或在方法執行之前/之後新增額外邏輯。
如何配置 NestJS 與 TypeORM?
使用 @nestjs/typeorm 套件。在 AppModule 中匯入 TypeOrmModule.forRoot(),在功能模組中匯入 TypeOrmModule.forFeature() 並附上實體陣列。
這個技能可以編寫完整的應用程式嗎?
此技能提供專業指導、程式碼模式和故障排除。它能幫助您理解和實作 NestJS 解決方案,而不是生成完整的應用程式。

開發者詳情

檔案結構

📄 SKILL.md