nodejs
Skill0 starsChanged 8 months agoMITView on GitHub
ALWAYS consult this skill before writing, editing, reviewing, or refactoring any Node.js code. It prevents the most common LLM-generated Node.js mistakes: bare 'fs'/'path' imports without the node: prefix, sync APIs (readFileSync) in async contexts, exec() shell injection, JSON.parse(JSON.stringify()) instead of structuredClone(), Math.random() instead of crypto.randomUUID(), missing graceful shutdown, and callback-style APIs when promise versions exist. Trigger on: any server-side JavaScript/TypeScript, CLI tools, scripts, Express/Fastify/Koa apps, anything importing fs/path/crypto/child_process/http/stream/worker_threads, package.json edits, require()-to-ESM refactors, or any mention of Node.js, npm, or server-side JS. Also trigger when you see code with require(), readFileSync, exec(), JSON.parse(JSON.stringify()), or Math.random() in a Node.js context — the skill tells you what to replace them with. Do NOT trigger for browser-only JS, React/Vue/Svelte components, Deno, or Bun-specific code.
7 other projects use a version of this.
Adopted by
Most recently taken up by
- rogue-dev-studio/ai-agents-roguetheir own version, first seen Nov 1, 2026
- G1Joshi/Agent-Skillstheir own version, first seen Oct 13, 2026
- conjure-3301/skillstheir own version, first seen Aug 17, 2026
- weiweimhy/agent-skillstheir own version, first seen Jul 1, 2026
- kimtth/agent-skill-100-lines-or-lesstheir own version, first seen Jun 26, 2026
- TheDecipherist/claude-code-mastery-project-starter-kittheir own version, first seen Jun 26, 2026
Used with
Projects with it also use grpc, gcp and 4 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
Sorcha-PlatformSkillgrpc
Build or review gRPC services and clients in .NET. USE FOR: ASP.NET Core gRPC, protobuf contracts, unary or streaming RPC, gRPC client factory, interceptors, deadlines, cancellation, channel reuse, backend service integration. DO NOT USE FOR: broad browser-facing APIs without gRPC-Web tradeoff review, SignalR realtime hubs, plain REST APIs. INVOKES: dotnet build/test and focused service or client smoke checks when code changes.
Also in 3 projects that use this
ffsshhttiikkSkillgcp
Google Cloud Platform services and best practices
Also in 3 projects that use this
VercelSkilloauth
Configure OAuth providers (Google, Apple, Microsoft, Facebook, GitHub, etc.) to work with portless local dev URLs. Use when setting up OAuth redirect URIs, fixing "redirect_uri_mismatch" or "invalid redirect" errors, configuring sign-in providers for local development, or when a provider rejects .localhost subdomains. Triggers include "OAuth not working with portless", "redirect URI mismatch", "Google/Apple/Microsoft sign-in fails locally", "configure OAuth for local dev", or any task involving OAuth callback URLs with portless domains.
Also in 3 projects that use this
JetBrainsSkillvue
Vue 3 Composition API, script setup macros, reactivity system, and built-in components. Use when writing Vue SFCs, defineProps/defineEmits/defineModel, watchers, or using Transition/Teleport/Suspense/KeepAlive.
Also in 4 projects that use this
MicrosoftSkillgithub-actions
Use when creating, editing, reviewing, or troubleshooting GitHub Actions workflows in Scope.
Also in 4 projects that use this
VercelSkillreact
React renderer for json-render that turns JSON specs into React components. Use when working with @json-render/react, building React UIs from JSON, creating component catalogs, or rendering AI-generated specs.
Also in 3 projects that use this
Other versions7 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 7
- TheDecipherist/claude-code-mastery-project-starter-kit★ 337same name
- G1Joshi/Agent-Skills★ 15same name
- ffsshhttiikk/opencode-agents-skills★ 2same name
- kimtth/agent-skill-100-lines-or-less★ 2same name
- rogue-dev-studio/ai-agents-rogue★ 2same name
- conjure-3301/skills★ 0same name
- weiweimhy/agent-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository2 other files it gives its agents.
- rustSkill
- typescriptSkill
The file
We split this skill into the rules it gives an agent
2 rules. 0 are common, 0 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 6 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 29
No
.then()chains: when async/await is available. - Very specific: line 30
Promise.allSettled()overPromise.all(): when partial failure is acceptable — Promise.all() rejects on the first failure and you lose …
“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Node.js Guardrails
These guardrails apply to all Node.js code you write, review, or modify. They exist because LLM-generated Node.js tends to repeat the same mistakes: missing node: prefixes, callback-style APIs when promise versions exist, unsafe exec() calls, sync fs operations in async contexts, and JSON.parse(JSON.stringify()) for deep copies. Following these rules produces code that's modern, secure, and idiomatic for Node.js 20+.
Imports
The node: prefix makes it unambiguous that you're importing a built-in module, not a npm package that happens to share the name. Node.js has had this prefix since v16 and it should be used everywhere.
- Always use the
node:prefix for built-in modules —import fs from 'node:fs/promises', notimport fs from 'fs'. This applies to every built-in:node:path,node:url,node:crypto,node:os,node:stream,node:child_process,node:util,node:events, etc. - Use
node:fs/promises— notnode:fswith callbacks. The promise-based API is cleaner and composes with async/await. - Use
node:pathfor all path operations — never concatenate strings with/. Paths are OS-dependent andpath.join()/path.resolve()handle this correctly. - Use
node:urland theURLclass for URL manipulation — not string concatenation or regex. - Use
node:cryptofor randomness — neverMath.random()for anything security-related (tokens, IDs, secrets).crypto.randomUUID()andcrypto.randomBytes()exist for this reason.
Async
Node.js is built around non-blocking I/O. Callbacks were the original API style, but modern Node.js has promise-based alternatives for everything. Using async/await makes code readable, debuggable, and composable.
- async/await everywhere — never callbacks unless forced by a legacy API that has no promise version.
- No
.then()chains when async/await is available..then()chains are harder to read, harder to debug (stack traces), and harder to compose with try/catch. Promise.allSettled()overPromise.all()when partial failure is acceptable —Promise.all()rejects on the first failure and you lose the results of the others.AbortController+AbortSignalfor cancellation — not custom boolean flags likelet cancelled = false. AbortSignal is the standard cancellation mechanism and integrates with fetch, streams, child processes, and timers.- Use
node:timers/promises—import { setTimeout } from 'node:timers/promises'gives you an awaitable timer directly. Don't wrapsetTimeoutinnew Promise().
// wrong
await new Promise(resolve => setTimeout(resolve, 1000));
// correct
import { setTimeout } from 'node:timers/promises';
await setTimeout(1000);Process
- No
process.exit()except in CLI entry points — in library code and most application code, throw an error or return an error value instead.process.exit()skips cleanup, kills pending I/O, and makes code untestable. - Use
process.exitCode = 1overprocess.exit(1)when possible — setting the exit code lets Node.js finish pending operations before exiting naturally. - Handle
SIGINTandSIGTERMin long-running processes (servers, workers, daemons) for graceful shutdown — close connections, flush buffers, release resources. structuredClone()for deep copy — notJSON.parse(JSON.stringify()). The JSON trick silently dropsundefined, functions,Dateobjects,Map,Set,RegExp, and circular references.structuredClone()handles all of these correctly.- Use
node:worker_threadsfor CPU-heavy work — notchild_processfor running JS code. Worker threads share memory (viaSharedArrayBuffer) and avoid the overhead of spawning a new process.
File System
Sync fs operations block the event loop. In a server or any async context, this means every other request stalls while you wait for disk I/O. The only acceptable place for sync fs is CLI startup where nothing else is running yet.
- Always
node:fs/promises— never sync fs operations (readFileSync,writeFileSync, etc.) except during CLI startup/initialization. - Specify encoding explicitly —
readFile(path, { encoding: 'utf-8' }), notreadFile(path)which returns a Buffer. mkdirwith{ recursive: true }— don't check existence withexistsSyncfirst and then create. The recursive option is idempotent and avoids race conditions.- Use
node:ostmpdir()for temp files — never hardcode/tmp. macOS uses/private/var/folders/..., Windows uses%TEMP%, and containers may mount tmpfs elsewhere.
import { mkdir, readFile, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
await mkdir(join(tmpdir(), 'my-app'), { recursive: true });
const content = await readFile(configPath, { encoding: 'utf-8' });Streams
Streams are powerful but notoriously error-prone when piped manually. A leaked error handler means an unhandled rejection that crashes your process. pipeline() handles backpressure, error propagation, and cleanup for you.
- Use
pipeline()fromnode:stream/promises— never.pipe()with manual error handling.pipeline()destroys all streams on error and returns a promise. - Prefer
node:stream/consumers(.text(),.json(),.buffer()) for consuming readable streams — these are built-in and handle encoding correctly. - Use
Readable.from()for creating streams from iterables — don't push data manually into a PassThrough stream.
import { pipeline } from 'node:stream/promises';
import { createReadStream, createWriteStream } from 'node:fs';
import { createGzip } from 'node:zlib';
await pipeline(
createReadStream('input.txt'),
createGzip(),
createWriteStream('input.txt.gz')
);Child Processes
Spawning a shell is a common source of injection vulnerabilities. exec() passes the command through /bin/sh, which means shell metacharacters in user input become code execution. execFile() bypasses the shell entirely.
execFileoverexec— avoid shell injection. If you need shell features (pipes, globbing), useexecexplicitly and sanitize inputs, but preferexecFileby default.- Always handle
stderr— don't ignore it. At minimum, log it. Silently swallowed stderr hides errors that make debugging impossible later. - Set
timeoutandmaxBufferon exec/execFile — runaway child processes can hang indefinitely or consume unbounded memory. - Use
signaloption with AbortController for cleanup — this lets you cancel child processes cleanly without resorting tokill.
import { execFile } from 'node:child_process';
import { promisify } from 'node:util';
const execFileAsync = promisify(execFile);
const controller = new AbortController();
const { stdout, stderr } = await execFileAsync('git', ['status'], {
timeout: 10_000,
maxBuffer: 1024 * 1024,
signal: controller.signal,
});Versions & Compatibility
- Target Node.js 20+ (LTS) minimum unless the project specifies otherwise. Don't use Node.js 18 patterns or polyfills for APIs that landed in v20.
- Use stable APIs — not experimental — unless explicitly needed. Check the Node.js docs stability index before recommending lesser-known APIs.
package.json
"type": "module"for ESM — all new Node.js projects should use ES modules."engines"field to declare the Node.js version requirement — this gives clear errors when someone tries to run the project on an unsupported version."exports"field for package entry points — not just"main". The"exports"field supports conditional exports (ESM/CJS), subpath exports, and blocks deep imports into internals."packageManager"field with corepack for pnpm/yarn version pinning — this ensures everyone on the team uses the same package manager version.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

