node
Guide for the Node.js runtime in TypeScript projects. Use when working with async/await and Promises, reading or writing streams, choosing between ESM and…
от vinnie357★ 30 звёзд на GitHub
Установить node в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Node.js Runtime
Async patterns, streams, module systems, package managers, and mise/CI integration for Node.js TypeScript projects.
Async Patterns
async/await over raw Promise chains
async function fetchUserAndPosts(userId: string) {
const user = await fetchUser(userId);
const posts = await fetchPosts(user.id);
return { user, posts };
}
Prefer await in sequence over .then() chains for anything with more than one step — the stack trace on a rejected await points at the actual failing line, where a long .then() chain's error frequently doesn't.
Concurrency with Promise.all / Promise.allSettled
Sequential await calls that don't depend on each other's results waste wall-clock time — run independent async work concurrently:
// Sequential — unnecessarily slow if these don't depend on each other
const user = await fetchUser(id);
const settings = await fetchSettings(id);
// Concurrent — same total work, shorter wall time
const [user, settings] = await Promise.all([fetchUser(id), fetchSettings(id)]);
Promise.all rejects as soon as any one input rejects, discarding the other results. Promise.allSettled never rejects — it resolves with a { status: "fulfilled" | "rejected", ... } record per input, appropriate when partial failure is an expected, handled case (e.g. "notify five webhooks, report which ones failed") rather than a hard error.
EventEmitter
Node's EventEmitter is the base of most non-stream async Node APIs (process, net.Server, child_process) — extend it for a custom object that fires multiple named events over its lifetime, as opposed to a Promise's single resolve/reject:
import { EventEmitter } from "node:events";
class JobQueue extends EventEmitter {
enqueue(job: Job) {
// ...
this.emit("enqueued", job);
}
}
const queue = new JobQueue();
queue.on("enqueued", (job: Job) => console.log(`queued ${job.id}`));
Reach for EventEmitter for "zero or more things will happen over time, listeners subscribe/unsubscribe" — reach for a Promise for "exactly one thing happens once." Mixing the two (a Promise that also emits progress events) is a common source of Node API confusion; if progress reporting is needed, an EventEmitter combined with a distinct completion Promise (or an async generator) is clearer than overloading one Promise for both jobs.
Streams
Four stream types, all EventEmitter subclasses under the hood:
| Type | Direction | Example |
|---|---|---|
Readable |
Data flows out | fs.createReadStream(), an HTTP response body |
Writable |
Data flows in | fs.createWriteStream(), process.stdout |
Duplex |
Both, independently | net.Socket |
Transform |
Both, output derived from input | zlib.createGzip() |
Piping
import { createReadStream, createWriteStream } from "node:fs";
import { createGzip } from "node:zlib";
createReadStream("input.txt")
.pipe(createGzip())
.pipe(createWriteStream("input.txt.gz"));
.pipe() is the default choice over manual data/end event listeners — it handles backpressure automatically, which manual event handling does not.
Backpressure
A Writable.write() call returns false when its internal buffer is full — code writing directly (not through .pipe()) must pause until the stream's 'drain' event fires, or memory grows unbounded on a fast producer / slow consumer:
function writeAll(stream: NodeJS.WritableStream, data: string, done: () => void) {
if (!stream.write(data)) {
stream.once("drain", done);
} else {
process.nextTick(done);
}
}
stream.pipeline() (from node:stream/promises) is the preferred modern API over chained .pipe() calls for anything that needs error propagation across the whole chain — a .pipe() chain does not automatically forward an error from an earlier stream to destroy later ones, pipeline() does.
ESM vs CommonJS
"type" field
{ "type": "module" }
"module"—.jsfiles are ES modules (import/export)"commonjs"or omitted —.jsfiles are CommonJS (require/module.exports).mjsis always ESM and.cjsis always CommonJS, regardless of"type"— use the explicit extension when a package needs to ship both formats in adjacent files.
Default new projects to "type": "module" — ESM is where the Node and browser ecosystems converge, and tsc --init on a current TypeScript release defaults "module" to "nodenext", which follows this field.
exports field
exports is both an encapsulation boundary (only listed paths are importable from outside the package — deep imports into unlisted internal files fail) and the mechanism for dual ESM/CJS publishing via conditional exports:
{
"name": "my-package",
"type": "module",
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
"./utils": {
"im
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- references/module-resolution.md
FAQ
Что делает скилл node?
Guide for the Node.js runtime in TypeScript projects. Use when working with async/await and Promises, reading or writing streams, choosing between ESM and CommonJS, configuring package.json exports, picking npm/pnpm/bun, managing Node versions with mise, or wiring Node CI/CD.
Как установить скилл node?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл node запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
AnthropicGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
academy-guide
AnthropicStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
internal-comms
AnthropicA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
skill-development
AnthropicThis skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…