node-best-practices

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

When to use

使用场景

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.
当你处理Node.js代码,需要获取构建健壮、高性能且可维护的Node.js应用的领域特定知识时,即可使用本技能。

TypeScript with Type Stripping

结合类型剥离的TypeScript使用

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:
  • Use
    import type
    for type-only imports
  • Use const objects instead of enums
  • Avoid namespaces and parameter properties
  • Use
    .ts
    extensions in imports
See rules/typescript.md for complete configuration and examples.
在为Node.js编写TypeScript代码时,使用type stripping(Node.js 22.6+)替代ts-node或tsx等构建工具。类型剥离会在运行时直接移除类型注解,无需转译即可运行TypeScript。
类型剥离兼容性的关键要求:
  • 对仅类型导入使用
    import type
  • 使用const对象替代枚举
  • 避免命名空间和参数属性
  • 在导入中使用.ts扩展名
完整配置和示例请查看rules/typescript.md

How to use

使用方法

Read individual rule files for detailed explanations and code examples:
  • rules/error-handling.md - Error handling patterns in Node.js
  • rules/async-patterns.md - Async/await and Promise patterns
  • rules/streams.md - Working with Node.js streams
  • rules/modules.md - ES Modules and CommonJS patterns
  • rules/testing.md - Testing strategies for Node.js applications
  • rules/flaky-tests.md - Identifying and diagnosing flaky tests with node:test
  • rules/node-modules-exploration.md - Navigating and analyzing node_modules directories
  • rules/performance.md - Performance optimization techniques
  • rules/caching.md - Caching patterns and libraries
  • rules/profiling.md - Profiling and benchmarking tools
  • rules/logging.md - Logging and debugging patterns
  • rules/environment.md - Environment configuration and secrets management
  • rules/graceful-shutdown.md - Graceful shutdown and signal handling
  • rules/typescript.md - TypeScript configuration and type stripping in Node.js
阅读单个规则文件以获取详细说明和代码示例:
  • rules/error-handling.md - Node.js中的错误处理模式
  • rules/async-patterns.md - Async/await与Promise模式
  • rules/streams.md - Node.js流的使用
  • rules/modules.md - ES模块与CommonJS模式
  • rules/testing.md - Node.js应用的测试策略
  • rules/flaky-tests.md - 使用node:test识别和诊断不稳定测试
  • rules/node-modules-exploration.md - 浏览和分析node_modules目录
  • rules/performance.md - 性能优化技巧
  • rules/caching.md - 缓存模式与库
  • rules/profiling.md - 性能分析与基准测试工具
  • rules/logging.md - 日志记录与调试模式
  • rules/environment.md - 环境配置与密钥管理
  • rules/graceful-shutdown.md - 优雅关闭与信号处理
  • rules/typescript.md - Node.js中的TypeScript配置与类型剥离