Index of every page on this site: llms.txt
All skills
mcollina avatar

/node

@c75d70d
by Matteo Collinamcollina/skills2k stars
146
Run it yourself

Provides domain-specific best practices for Node.js development with TypeScript, covering type stripping, async patterns, error handling, streams, modules, testing, performance, caching, logging, and more. Use when setting up Node.js projects with native TypeScript support, configuring type stripping (--experimental-strip-types), writing Node 22+ TypeScript without a build step, or when the user mentions 'native TypeScript in Node', 'strip types', 'Node 22 TypeScript', '.ts files without compilation', 'ts-node alternative', or needs guidance on error handling, graceful shutdown, flaky tests, profiling, or environment configuration in Node.js. Helps configure tsconfig.json for type stripping, set up package.json scripts, handle module resolution and import extensions, and apply robust patterns across the full Node.js stack.

Use this Skill: https://skilld.dev/gh/mcollina/skills/node

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

rulesstuck-processes-and-tests.md

≈998 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Diagnosing Stuck Node.js Processes and Hanging Tests

Activation triggers (apply this rule immediately)

Use this rule when prompts/logs include any of:

  • "node --test hangs" / "test run never exits"
  • "CI timed out" after tests appear done
  • "process is still running" / "did not exit cleanly"
  • "open handles" / "active handles"
  • "passes alone, hangs in full suite"

Non-negotiable checklist (all 5 required)

  1. Isolate first: reproduce with one file, then one test name.
  2. Fail fast: run with explicit timeout + reporter so hangs produce location context.
  3. Capture handles: run why-is-node-running and record the reported handle owner.
  4. Patch teardown in the same scope that created the resource (t.after(...), await close/terminate/disconnect).
  5. Verify stability: repeat isolated test many times, then run full suite.

Do not mark the issue fixed unless step 5 passes.

Command path (run in order)

# 1) Reproduce full command with fail-fast settings
node --test --test-reporter=spec --test-timeout=15000

# 2) Isolate file, then test name
node --test --test-timeout=15000 path/to/file.test.ts
node --test --test-timeout=15000 --test-name-pattern="should close resources" path/to/file.test.ts

# 3) Dump active handles when hung
node --import why-is-node-running/include --test path/to/file.test.ts
# in another shell, send SIGUSR1 to printed PID
kill -SIGUSR1 <pid>

# 4) Stress rerun isolated repro (Linux: timeout, macOS: gtimeout)
TIMEOUT_BIN="$(command -v timeout || command -v gtimeout)"
for i in {1..30}; do
  "$TIMEOUT_BIN" 30s node --test path/to/file.test.ts || { echo "failed on run $i"; break; }
done

why-is-node-running install note

  • ESM / modern Node: npm i -D why-is-node-running
  • older CommonJS projects: npm i -D why-is-node-running@v2

Use it for diagnostics only; gate noisy output behind an environment flag in CI.

High-probability root causes

  • HTTP server started but never closed (server.close() not awaited)
  • setInterval left running (or timer not unref()ed when appropriate)
  • DB/Redis/Kafka clients not disconnected
  • worker threads, child processes, or message channels left alive
  • file watchers / readline interfaces still open
  • unresolved promises from fire-and-forget async code
  • teardown hooks that throw before cleanup completes

Integrated fix example (CI hangs after tests appear complete)

Symptom: CI times out; local full-suite run hangs after most tests pass.

Step sequence

  1. Reproduce with:
    node --test --test-reporter=spec --test-timeout=15000
  2. Isolate to one test using --test-name-pattern.
  3. Run with --import why-is-node-running/include and send SIGUSR1.
  4. Patch teardown where resource is created.
  5. Verify isolated 30x, then full suite.

Bad (common leak)

it('serves requests', async () => {
  const server = await startServer({ port: 0 });
  const id = setInterval(() => {}, 1000);
  // test body...
  // ❌ no deterministic teardown
});

Good (deterministic teardown)

import { once } from 'node:events';

it('serves requests', async (t) => {
  const server = await startServer({ port: 0 });
  const id = setInterval(() => {}, 1000);

  t.after(async () => {
    clearInterval(id);
    server.close();
    await once(server, 'close');
  });

  // test body...
});

Definition of done (must all pass)

  • Isolated repro passes repeatedly (recommended: 30 runs) with no hangs
  • Full node --test run exits with code 0
  • CI completes with no timeout
  • why-is-node-running shows no unexpected leftover handles

Related rules

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning2mo5 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    This skill provides a comprehensive set of Node.js best practices and design patterns, focusing on performance, observability, and robust architecture. No security issues were detected.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

  • Runlayer8mo

    2/17 files flagged

  • ZeroLeaks7mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at c75d70d. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Activeupdated 9 months ago
Other metadata
metadata
{
  "tags": "node, nodejs, javascript, typescript, type-stripping, backend, server"
}

README badge

README badge for mcollina/skills/node