nodejs-best-practices

A set of guidance for choosing Node.js tools, runtime settings, module formats, and application structures. Node.js is software for running JavaScript outside a web browser.

In plain words
What is it for?
Planning Node.js projects, comparing Hono, Fastify, Express, NestJS, and related options, and deciding between Node.js, Bun, or Deno.
Why use it?
It helps avoid choosing a framework or project setup by habit when the deployment target, team experience, or existing code calls for something different.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/misonl/ling/nodejs-best-practices
Any agent
npx skills add MisonL/Ling --skill nodejs-best-practices
Clone the repo
git clone --depth 1 https://github.com/MisonL/Ling

Made for: Claude Code, Codex.

Per session 41 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,449 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00041 $0.02449
Opus 5 $0.00020 $0.01224
Sonnet 5 $0.00008 $0.00490
Haiku 4.5 $0.00004 $0.00245

Measured 2d ago against content hash afd79a57be0c, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

nodejs-best-practices scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.agents/skills/nodejs-best-practices/SKILL.md · 334 lines

How it starts

The opening of the file, as written. The whole thing — 334 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Node.js 最佳实践

面向 2025 的 Node.js 开发原则与决策方法。
学习如何思考,不要只记代码套路。


[WARN] 本技能使用方式

本技能教授的是决策原则,不是固定代码模板。

  • 需求不明确时,先向用户确认偏好
  • 根据上下文(Context)选择框架与模式
  • 不要每次都默认同一套方案

1. 框架选型(2025)

决策树

你要构建什么?
|
+-- Edge/Serverless(边缘/无服务器,Cloudflare、Vercel)
|   +-- Hono(零依赖、冷启动极快)
|
+-- 高性能 API
|   +-- Fastify(通常比 Express 快 2-3 倍)
|
+-- 企业协作/团队熟悉度优先
|   +-- NestJS(结构化、DI、装饰器)
|
+-- 传统/稳定/生态最大化
|   +-- Express(成熟、middleware 最多)
|
+-- 前后端一体
    +-- Next.js API Routes 或 tRPC

对比原则

维度 Hono Fastify Express
适用场景 Edge、serverless 性能优先 传统、学习
冷启动 最快 中等
生态 成长中 较好 最大
TypeScript 原生支持 优秀 良好
学习曲线

选型前必须询问:

  1. 部署目标是什么?
  2. 冷启动时间是否关键?
  3. 团队是否有既有经验?
  4. 是否存在需要维护的遗留代码?

2. 运行时考量(2025)

原生 TypeScript

Node.js 22+: --experimental-strip-types
+-- 可直接运行 .ts 文件
+-- 简单项目可免构建步骤
+-- 适用:脚本、简单 API

模块系统决策

ESM(import/export)
+-- 现代标准
+-- 更好的 tree-shaking
+-- 异步模块加载
+-- 适用:新项目

CommonJS(require)
+-- 遗留兼容性更好
+-- 对部分 npm 包支持更成熟
+-- 适用:既有代码库、特定边界场景

Runtime 选择

Runtime 适用场景
Node.js 通用场景、生态最大
Bun 性能优先、内置 bundler
Deno 安全优先、内置 TypeScript

3. 架构原则

分层结构概念

请求流(Request Flow):
|
+-- Controller/Route 层
|   +-- 处理 HTTP 细节
|   +-- 在边界做输入校验
|   +-- 调用 service 层
|
+-- Service 层
|   +-- 承载业务逻辑
|   +-- 与框架解耦
|   +-- 调用 repository 层
|
+-- Repository 层
    +-- 仅处理数据访问
    +-- 数据库查询
    +-- ORM 交互

为什么重要

  • 可测性(Testability): 可独立 mock 每一层
  • 灵活性(Flexibility): 更换数据库不影响业务层
  • 清晰性(Clarity): 每层职责单一

何时简化

  • 小型脚本 -> 单文件可接受
  • 原型验证 -> 可降低结构复杂度
  • 始终追问:“这个项目会继续增长吗?”

4. 错误处理原则

集中式错误处理

Pattern:
+-- 定义自定义错误类
+-- 各层都可 throw
+-- 在顶层统一 catch(middleware)
+-- 输出一致的响应格式

错误响应哲学

Client gets:
+-- 合理的 HTTP 状态码
+-- 可程序化处理的错误码
+-- 对用户友好的提示
+-- 不暴露内部细节(安全要求)

Logs get:
+-- 完整堆栈信息
+-- 请求上下文
+-- 用户 ID(如适用)
+-- 时间戳

状态码选择

Read the full file on GitHub · 334 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 334 lines · 41 tokens per session scan A afd79a57be0c

Subscribe to this mod's changes

nodejs-best-practices is a skill published in the GitHub repository MisonL/Ling (9 stars, last pushed 5mo ago), licensed MIT. It adds 41 tokens to every session and 2,449 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

systematic-debugging

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes.

obra/superpowers · 21 tokens

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, or modifying behavior. Explores user intent, requirements and design before implementation.

obra/superpowers · 37 tokens

auto-perf-optimize

Run agent-driven VS Code performance or memory investigations. Use when asked to launch Code OSS, automate a VS Code scenario, run the Chat memory smoke runner, capture renderer heap snapshots, take workflow screenshots, compare run summaries, or drive a repeatable scenario before heap-snapshot analysis.

microsoft/vscode · 62 tokens

chat-perf

Run chat perf benchmarks and memory leak checks against the local dev build or any published VS Code version. Use when investigating chat rendering regressions, validating perf-sensitive changes to chat UI, or checking for memory leaks in the chat response pipeline.

microsoft/vscode · 51 tokens

chat-pet-sprite-creation

Use when creating or changing VS Code chat pet sprite art, sprite sheets, state animations, eye treatments, Stable/Insiders variants, or pet transitions under src/vs/workbench/contrib/chat/browser/widget/media/chatPet.

microsoft/vscode · 53 tokens

cpu-profile-analysis

Analyze V8/Chrome CPU profiles (.cpuprofile) and DevTools trace files (Trace-.json). Use when: profiling performance, investigating slow functions, comparing code paths, finding bottlenecks, analyzing timeToRequest, understanding call trees from sampling profiler data, analyzing layout/paint/rendering, investigating…

microsoft/vscode · 71 tokens