Node modern

From WrongStack/WrongStack · View interactive version

Node modern is an AI agent skill from the GitHub repository WrongStack/WrongStack. Node.js runtime code: ESM/CommonJS, async flow, AbortSignal cancellation, streams, fs, child_process, fetch and the event loop. Use this skill when writing, reviewing, or refactoring Node.js code — modules, async flow, cancellation, file and process I/O, HTTP — on a current Node.js release. Triggers

How to use this skill

Skill file

Modern Node.js

Selection card

Overview

Node.js 26.13.0 (newest stable; LTS 26.13.0 since 2026-10-28, Node 24 in maintenance; checked 2026-11-02) ships natively what older code pulled from npm:

native TypeScript type stripping (node file.ts), native .env

loading (node --env-file), built-in SQLite (node:sqlite), global WebSocket,

Promise.withResolvers(), global fetch, AbortSignal.timeout, node:test, Web Streams,

and node --run. Prefer the platform when its semantics fit; do not remove needed capabilities merely to reduce dependency count.

Rules

  1. Pre-flight: Inspect repo runtime & live Node.js LTS schedule first. Check package.json

"engines", .nvmrc, .node-version, and check node -v to determine the active engine.

Check the official Node.js release schedule online to ensure target runtime aligns with

active LTS or the requested latest stable channel; verify support status from the current release schedule.

  1. Match the module system. In an ESM package ("type": "module" or .mjs)

write ES import statements, with explicit file extensions on relative imports when the

project compiles with NodeNext. Don't convert a CommonJS package to ESM as a

side effect of another change.

  1. Import built-ins with the node: prefix (node:fs/promises, node:path, node:sqlite).
  2. Prefer native platform features over npm bloat:
  1. Give every operation that can wait a deadline: pass an AbortSignal to

fetch calls, child processes, and timers; combine user cancellation with a

timeout using AbortSignal.any.

  1. Handle ENOENT by reading inside try/catch and branching on err.code;

checking access first is a race (TOCTOU).

  1. Never block the event loop in a server or CLI hot path: no *Sync fs calls

or CPU-heavy loops on request paths.

  1. Pass arguments to child processes as an array (execFile/spawn), never by

interpolating into a shell string.

  1. Every promise is awaited, returned, or explicitly handled; let entry points

report unhandled rejections instead of swallowing them.

Patterns

import { execFile } from 'node:child_process';
import { randomBytes } from 'node:crypto';
import { readFile, rename, writeFile } from 'node:fs/promises';
import { setTimeout as delay } from 'node:timers/promises';
import { promisify } from 'node:util';

const execFileAsync = promisify(execFile);

// Deadline plus user cancellation.
export async function getJson(url: string, signal?: AbortSignal): Promise<unknown> {
  const deadline = AbortSignal.timeout(10_000);
  const res = await fetch(url, { signal: signal ? AbortSignal.any([signal, deadline]) : deadline });
  if (!res.ok) throw new Error(`GET ${url} failed with ${res.status}`);
  return res.json();
}

// Missing file is an expected outcome, not an exception.
export async function readOptional(path: string): Promise<string | undefined> {
  try {
    return await readFile(path, 'utf8');
  } catch (err) {
    if ((err as NodeJS.ErrnoException).code === 'ENOENT') return undefined;
    throw err;
  }
}

// Atomic replace: readers never observe a half-written file.
export async function writeAtomic(target: string, data: string): Promise<void> {
  const tmp = `${target}.${randomBytes(4).toString('hex')}.tmp`;
  await writeFile(tmp, data);
  await rename(tmp, target);
}

// Cancellable delay — the promise API takes a signal; the global setTimeout does not.
await delay(500, undefined, { signal: AbortSignal.timeout(5_000) });

// Arguments as an array — no shell, no injection.
const { stdout } = await execFileAsync('git', ['log', '--oneline', '-5'], {
  signal: AbortSignal.timeout(15_000),
});

// Partial failure is acceptable: collect every outcome.
const results = await Promise.allSettled(urls.map((url) => getJson(url)));
const failed = results.filter((r) => r.status === 'rejected');

In ESM, __dirname doesn't exist: use import.meta.dirname on current Node, or

path.dirname(fileURLToPath(import.meta.url)) on older releases.

Anti-patterns

| Anti-pattern | Why it hurts | Instead |

|---|---|---|

| fetch(url) with no signal | Hangs forever on a stalled server | AbortSignal.timeout() |

| exec(\cmd ${input}\) | Shell injection | execFile with an argument array |

| existsSync then readFile | Race between check and use | try/catch on the read |

| readFileSync in a request handler | Blocks every other request | node:fs/promises |

| Catching an AbortError and continuing silently | Hides timeouts and cancellations | Rethrow, or report it as a timeout |

| writeFile directly over a config or state file | A crash leaves it truncated | Write to a temp file, then rename |

Before returning

Current runtime and ownership

Latest stable checked 2026-11-02: Node.js 26.13.0 (LTS 26.13.0; Node 24 in maintenance), Bun 1.4.4,

pnpm 12.16.1. Refresh the official release/registry before recommendations.

nodejs.org/dist/index.json also lists alpha and Current builds; name the channel you checked.

Native TypeScript execution strips supported syntax; it does not typecheck or

implement tsconfig path aliases. Verify the real module/resolution contract.

Native WebSocket is a client API; server behavior may require a dependency.

For atomic replacement, use an exclusively created temp file in the same

directory and clean only owned intermediates on failure. Rename is not durability,

cross-filesystem atomicity or concurrency control. Recheck generation after awaits.

Skills in scope

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.