npx skills add https://github.com/mcollina/skills --skill node-best-practices在处理 Node.js 代码时,请使用此技能,以获取构建健壮、高性能且可维护的 Node.js 应用程序所需的领域特定知识。
在为 Node.js 编写 TypeScript 时,请使用类型剥离(Node.js 22.6+),而不是 ts-node 或 tsx 等构建工具。类型剥离通过运行时移除类型注解来直接运行 TypeScript,而无需转译。
类型剥离兼容性的关键要求:
import type.ts 扩展名最小示例 — 一个有效的类型剥离 TypeScript 文件:
// greet.ts
import type { IncomingMessage } from 'node:http';
const greet = (name: string): string => `Hello, ${name}!`;
console.log(greet('world'));
直接运行:
node greet.ts
完整配置和示例请参见 rules/typescript.md。
对于多步骤流程,在查阅相关规则文件之前,请遵循以下高级顺序:
:注册信号处理器(SIGTERM/SIGINT)→ 停止接受新工作 → 排空进行中的请求 → 关闭外部连接(数据库、缓存)→ 以适当的代码退出。参见 。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
错误处理 :定义共享的错误基类 → 对错误进行分类(操作错误与程序员错误)→ 添加异步边界处理器(process.on('unhandledRejection'))→ 通过调用栈传播类型化错误 → 在响应或崩溃前记录上下文信息。参见 rules/error-handling.md。
诊断不稳定的测试 :使用 --test-only 隔离测试 → 检查共享状态或计时器依赖 → 检查异步清理顺序 → 添加重试逻辑作为临时诊断步骤 → 修复根本原因。参见 rules/flaky-tests.md。
分析慢速路径 :在真实负载下复现 → 使用 --cpu-prof 捕获 CPU 性能分析文件 → 识别热点函数 → 检查流反压或不必要的序列化 → 通过基准测试验证改进。参见 rules/profiling.md 和 rules/performance.md。
阅读各个规则文件以获取详细解释和代码示例:
每周安装量
404
代码仓库
GitHub 星标数
1.6K
首次出现
2026年1月31日
安全审计
安装于
codex388
opencode385
github-copilot384
gemini-cli383
kimi-cli377
amp377
Use this skill whenever you are dealing with Node.js code to obtain domain-specific knowledge for building robust, performant, and maintainable Node.js applications.
When writing TypeScript for Node.js, use type stripping (Node.js 22.6+) instead of build tools like ts-node or tsx. Type stripping runs TypeScript directly by removing type annotations at runtime without transpilation.
Key requirements for type stripping compatibility:
import type for type-only imports.ts extensions in importsMinimal example — a valid type-stripped TypeScript file:
// greet.ts
import type { IncomingMessage } from 'node:http';
const greet = (name: string): string => `Hello, ${name}!`;
console.log(greet('world'));
Run directly with:
node greet.ts
See rules/typescript.md for complete configuration and examples.
For multi-step processes, follow these high-level sequences before consulting the relevant rule file:
Graceful shutdown : Register signal handlers (SIGTERM/SIGINT) → stop accepting new work → drain in-flight requests → close external connections (DB, cache) → exit with appropriate code. See rules/graceful-shutdown.md.
Error handling : Define a shared error base class → classify errors (operational vs programmer) → add async boundary handlers (process.on('unhandledRejection')) → propagate typed errors through the call stack → log with context before responding or crashing. See rules/error-handling.md.
Diagnosing flaky tests : Isolate the test with --test-only → check for shared state or timer dependencies → inspect async teardown order → add retry logic as a temporary diagnostic step → fix root cause. See rules/flaky-tests.md.
Profiling a slow path : Reproduce under realistic load → capture a CPU profile with --cpu-prof → identify hot functions → check for stream backpressure or unnecessary serialisation → validate improvement with a benchmark. See rules/profiling.md and rules/performance.md.
Read individual rule files for detailed explanations and code examples:
Weekly Installs
404
Repository
GitHub Stars
1.6K
First Seen
Jan 31, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex388
opencode385
github-copilot384
gemini-cli383
kimi-cli377
amp377
Swift Actor 线程安全持久化:构建离线优先应用的编译器强制安全数据层
1,200 周安装