nodejs
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese<EXTREMELY-IMPORTANT>
This skill is a routing shell over the Node.js/Bun reference set.
Non-negotiable rules:
- Read first to determine the runtime (Node.js or Bun), framework, and locked decisions.
references/stack.md - Then load only the references needed for the actual task.
- TypeScript strict mode — no , no implicit returns, no unchecked index access.
any - All async functions must handle errors — no unhandled promise rejections. Use try/catch or at every boundary.
.catch() - Input validation at system boundaries — Zod schemas on every external input (request bodies, query params, env vars, CLI args). Never trust .
req.body - Structured logging via pino — no in production code. JSON to stdout, parsed by log aggregators.
console.log - Graceful shutdown — handle SIGTERM/SIGINT, drain connections, finish in-flight work, close DB pools.
- No secrets in code or logs — env vars validated at startup, never logged, never in error responses.
<EXTREMELY-IMPORTANT>
本技能是基于 Node.js/Bun 参考集的路由外壳。
不可违背的规则:
- 首先阅读 以确定运行时(Node.js 或 Bun)、框架及已锁定的决策。
references/stack.md - 仅加载实际任务所需的参考内容。
- TypeScript 严格模式 — 禁止使用 、禁止隐式返回、禁止未检查的索引访问。
any - 所有异步函数必须处理错误 — 禁止未处理的 Promise 拒绝。在每个边界使用 try/catch 或 。
.catch() - 系统边界处的输入校验 — 对所有外部输入(请求体、查询参数、环境变量、CLI 参数)使用 Zod 模式。绝不信任 。
req.body - 通过 pino 实现结构化日志 — 生产代码中禁止使用 。输出 JSON 到标准输出,由日志聚合器解析。
console.log - 优雅停机 — 处理 SIGTERM/SIGINT 信号,排空连接,完成正在进行的工作,关闭数据库连接池。
- 代码或日志中不得包含密钥 — 环境变量在启动时校验,绝不记录,绝不包含在错误响应中。
nodejs
nodejs
Inputs
输入
- : The backend task, subsystem, bug, or feature being worked on
$request
- : 后端任务、子系统、Bug 或待开发功能
$request
Goal
目标
Route Node.js/Bun backend work through the project's conventions so implementation follows the established patterns for server architecture, data access, error handling, and deployment.
按照项目规范处理 Node.js/Bun 后端工作,确保实现遵循服务端架构、数据访问、错误处理及部署的既定模式。
Step 0: Read the stack contract
步骤 0:阅读栈合约
Always start with:
references/stack.md
That establishes: runtime (Node.js or Bun), framework (Express/Fastify/Hono/none), ORM, test runner, package manager, and locked dependency choices.
If or exists, the runtime is Bun — also load for native API differences.
bun.lockbbunfig.tomlreferences/bun-runtime.mdSuccess criteria: The project's runtime, framework, and toolchain choices are explicit before implementation starts.
始终从以下内容开始:
references/stack.md
该文件定义了:运行时(Node.js 或 Bun)、框架(Express/Fastify/Hono/无)、ORM、测试运行器、包管理器及已锁定的依赖选择。
如果存在 或 ,则运行时为 Bun — 同时加载 了解原生 API 的差异。
bun.lockbbunfig.tomlreferences/bun-runtime.md成功标准:在开始实现前,明确项目的运行时、框架及工具链选择。
Step 1: Load only the relevant references
步骤 1:仅加载相关参考内容
Use the routing table to pick reference files. Do not bulk-load the full reference tree.
| Task | Read |
|---|---|
| Runtime, TypeScript, package manager, locked deps | |
| Folder conventions, entry points, monorepo layout | |
| Express/Fastify/Hono patterns, middleware, routing | |
| REST conventions, versioning, pagination, error responses | |
| Zod/AJV input validation, DTO patterns | |
| Prisma/Drizzle/Knex, migrations, connection pooling | |
| JWT, sessions, OAuth2, RBAC, middleware guards | |
| Error classes, async error boundaries, HTTP error responses | |
| pino structured logging, request correlation, log levels | |
| vitest/jest/bun test, supertest, test factories, coverage | |
| Promises, streams, worker threads, AbortController, shutdown | |
| helmet, CORS, rate limiting, input sanitization, dep audit | |
| Redis, in-memory caching, cache invalidation patterns | |
| BullMQ, job patterns, retry strategies, dead-letter queues | |
| Env validation, dotenv, config modules, secrets management | |
| OpenTelemetry, health checks, metrics, distributed tracing | |
| Multi-stage Dockerfile, .dockerignore, prod vs dev images | |
| ws/Socket.io, connection lifecycle, scaling, rooms | |
| commander/yargs, argument parsing, exit codes, stdin/stdout | |
| Bun-native APIs, bun test, bun build, Bun.serve, Bun.$ | |
Multiple tasks? Read multiple files. The references are self-contained.
Success criteria: Only the task-relevant backend conventions are in play.
使用路由表选择参考文件。不要批量加载完整的参考树。
| 任务 | 阅读内容 |
|---|---|
| 运行时、TypeScript、包管理器、已锁定依赖 | |
| 文件夹规范、入口点、单仓库布局 | |
| Express/Fastify/Hono 模式、中间件、路由 | |
| REST 规范、版本控制、分页、错误响应 | |
| Zod/AJV 输入校验、DTO 模式 | |
| Prisma/Drizzle/Knex、迁移、连接池 | |
| JWT、会话、OAuth2、RBAC、中间件守卫 | |
| 错误类、异步错误边界、HTTP 错误响应 | |
| pino 结构化日志、请求关联、日志级别 | |
| vitest/jest/bun test、supertest、测试工厂、覆盖率 | |
| Promise、流、工作线程、AbortController、停机 | |
| helmet、CORS、速率限制、输入 sanitization、依赖审计 | |
| Redis、内存缓存、缓存失效模式 | |
| BullMQ、任务模式、重试策略、死信队列 | |
| 环境变量校验、dotenv、配置模块、密钥管理 | |
| OpenTelemetry、健康检查、指标、分布式追踪 | |
| 多阶段 Dockerfile、.dockerignore、生产 vs 开发镜像 | |
| ws/Socket.io、连接生命周期、扩容、房间 | |
| commander/yargs、参数解析、退出码、标准输入/输出 | |
| Bun 原生 API、bun test、bun build、Bun.serve、Bun.$ | |
多个任务?阅读多个文件。参考内容是独立的。
成功标准:仅应用与任务相关的后端规范。
Step 2: Implement with the core backend guardrails
步骤 2:遵循核心后端约束实现
Keep these rules active:
- TypeScript strict mode with
noUncheckedIndexedAccess - all external input validated at the boundary (Zod schemas)
- errors are typed, caught, and returned as structured HTTP responses
- logging via pino child loggers with request correlation IDs
- database access through the project's ORM/query builder, not raw SQL strings
- mutations wrapped in transactions where atomicity matters
- graceful shutdown: SIGTERM handler drains server, closes pools, exits cleanly
- env vars validated at startup — fail fast on missing required config
- no , no
anytype assertions unless justified with a commentas - if Bun runtime: prefer ,
Bun.serve(),Bun.file()over Node.js equivalentsbun test
Success criteria: The change matches the project's backend architecture instead of generic defaults.
始终遵守以下规则:
- 启用 的 TypeScript 严格模式
noUncheckedIndexedAccess - 所有外部输入在边界处校验(使用 Zod 模式)
- 错误被类型化、捕获并作为结构化 HTTP 响应返回
- 通过带有请求关联 ID 的 pino 子记录器记录日志
- 通过项目的 ORM/查询构建器访问数据库,不使用原始 SQL 字符串
- 在需要原子性的场景下,将变更包裹在事务中
- 优雅停机:SIGTERM 处理器排空服务器、关闭连接池、干净退出
- 环境变量在启动时校验 — 缺少必要配置时快速失败
- 禁止使用 ,除非有注释说明理由,否则禁止使用
any类型断言as - 如果是 Bun 运行时:优先使用 、
Bun.serve()、Bun.file()而非 Node.js 等效 APIbun test
成功标准:变更符合项目后端架构,而非通用默认值。
Step 3: Verify the affected surface
步骤 3:验证受影响的范围
Use the narrowest relevant verification:
- unit tests (,
vitest run, orjest)bun test - integration tests with supertest or actual HTTP calls
- type checking ()
tsc --noEmit - linting ()
eslint . - if Docker: build the image and verify it starts
Success criteria: The changed backend surface still builds, type-checks, and passes tests.
使用最窄范围的相关验证:
- 单元测试(、
vitest run或jest)bun test - 使用 supertest 或实际 HTTP 调用的集成测试
- 类型检查()
tsc --noEmit - 代码检查()
eslint . - 如果使用 Docker:构建镜像并验证其能启动
成功标准:变更后的后端代码仍可构建、通过类型检查并通过测试。
Guardrails
约束
- Do not inline the whole Node.js handbook in .
SKILL.md - Do not skip .
references/stack.md - Do not use in production code — use pino.
console.log - Do not bypass input validation at API boundaries.
- Do not leave unhandled promise rejections.
- Do not hardcode secrets, ports, or environment-specific values.
- Do not add ; this is a normal domain skill.
disable-model-invocation
- 不要在 中嵌入完整的 Node.js 手册。
SKILL.md - 不要跳过 。
references/stack.md - 生产代码中禁止使用 — 使用 pino。
console.log - 不要绕过 API 边界处的输入校验。
- 不要留下未处理的 Promise 拒绝。
- 不要硬编码密钥、端口或环境特定值。
- 不要添加 ;这是一个常规领域技能。
disable-model-invocation
When To Load References
何时加载参考内容
-
Always.
references/stack.md -
When the project uses Bun (detected via
references/bun-runtime.mdorbun.lockb).bunfig.toml -
then only the task-relevant files under
references/
-
始终加载。
references/stack.md -
当项目使用 Bun 时(通过
references/bun-runtime.md或bun.lockb检测)。bunfig.toml -
然后仅加载下与任务相关的文件
references/
Output Contract
输出约定
Report:
- which references were loaded
- the architecture pattern chosen
- the change made
- the verification run
报告:
- 加载了哪些参考内容
- 选择的架构模式
- 做出的变更
- 执行的验证