npx skills add https://github.com/mcollina/skills --skill node在处理 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 开发者,精准高效
错误处理 :定义共享的错误基类 → 对错误进行分类(操作错误 vs 程序员错误)→ 添加异步边界处理器(process.on('unhandledRejection'))→ 在调用栈中传播类型化错误 → 在响应或崩溃前记录上下文。参见 rules/error-handling.md。
诊断不稳定的测试 :使用 --test-only 隔离测试 → 检查共享状态或计时器依赖 → 检查异步清理顺序 → 添加重试逻辑作为临时诊断步骤 → 修复根本原因。参见 rules/flaky-tests.md。
诊断卡住的进程/测试(node --test 挂起、"process did not exit"、CI 超时、打开的句柄):隔离文件/测试 → 使用显式超时/报告器运行 → 通过 why-is-node-running(SIGUSR1)检查句柄 → 在资源创建作用域内修补确定性清理 → 重新运行隔离测试和完整套件直至稳定。参见 rules/stuck-processes-and-tests.md。
分析慢路径 :在真实负载下复现 → 使用 --cpu-prof 捕获 CPU 性能分析 → 识别热点函数 → 检查流背压或不必要的序列化 → 通过基准测试验证改进。参见 rules/profiling.md 和 rules/performance.md。
当任务提及 CSV、ETL、数据摄取管道、大文件处理、背压、重复查找 或 去重并发异步调用 时,请明确应用此检查清单:
node:stream/promises 的 await pipeline(...)(在指导/代码中优先使用此方法而非链式 .pipe())。async function* 转换。lru-cache。async-cache-dedupe。pipeline() 隐式处理或通过 drain 显式处理)。对于 CSV/ETL 风格的提示,优先采用如下答案结构:
createReadStream(input)async function* 解析器/转换器async-cache-dedupe 或 lru-cache)await pipeline(...) 到可写目标在解释中直接链接相关规则,以便模型可以检索详细信息:
阅读各个规则文件以获取详细解释和代码示例:
每周安装量
253
代码仓库
GitHub 星标数
1.5K
首次出现
11 天前
安全审计
安装于
github-copilot245
codex245
cursor243
opencode242
kimi-cli239
gemini-cli239
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.
Diagnosing stuck processes/tests (node --test hangs, "process did not exit", CI timeout, open handles): isolate file/test → run with explicit timeout/reporter → inspect handles via why-is-node-running (SIGUSR1) → patch deterministic teardown in resource-creation scope → rerun isolated + full suite until stable. See rules/stuck-processes-and-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.
When the task mentions CSV , ETL , ingestion pipelines , large file processing , backpressure , repeated lookups , or deduplicating concurrent async calls , explicitly apply this checklist:
await pipeline(...) from node:stream/promises (prefer this over chained .pipe() in guidance/code).async function* transform when data is being transformed in-stream.lru-cache for bounded in-memory reuse in a single process.async-cache-dedupe for async request deduplication / stale-while-revalidate behavior.pipeline() or explicitly via drain).For CSV/ETL-style prompts, prefer an answer structure like:
createReadStream(input)async function* parser/transformasync-cache-dedupe or lru-cache)await pipeline(...) to a writable destinationLink relevant rules directly in explanations so models can retrieve details:
Read individual rule files for detailed explanations and code examples:
Weekly Installs
253
Repository
GitHub Stars
1.5K
First Seen
11 days ago
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
github-copilot245
codex245
cursor243
opencode242
kimi-cli239
gemini-cli239
GSAP 框架集成指南:Vue、Svelte 等框架中 GSAP 动画最佳实践
1,700 周安装