agentleFS
G1JoshiG1Joshi/Agent-Skills/skills/frameworks/nodejs/SKILL.md

nodejs

Skill15 starsChanged 42 days agoMITView on GitHub

Expert Node.js assistance covering asynchronous event loop, streams, worker threads, buffer manipulation, and ESM. Use when building scalable backend services, CLI utilities, or network servers.

7 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 0 are distinctive, and 4 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.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use stream.pipeline for automatic backpressure management:

    line 110
  2. Very specific:

    Use the node: protocol prefix (import fs from 'node:fs') for all built-in modules.

    line 132
  3. Very specific:

    Use node:stream/promises and pipeline to handle stream backpressure and error propagation.

    line 133
  4. Very specific:

    Use CommonJS (require()) in greenfield applications.

    line 139

“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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Node.js

Node.js is a cross-platform asynchronous event-driven JavaScript runtime, featuring a built-in Test Runner, native WebSocket client, and modern ESM module execution.

When to Use

  • Scalable Asynchronous Microservices: Building event-driven I/O-intensive web APIs on Node.js 22 LTS.
  • Real-Time Data Streaming & WebSockets: Processing streaming data using native node:stream and Transform streams.
  • CLI Development & Build Tooling: Building developer tools, linters, and deployment automations with npm.
  • Worker Threads & CPU-Bound Offloading: Offloading cryptographic hashing, compression, and image manipulation.

Quick Start

// Native Test Runner (No Jest needed)
import { test, assert } from "node:test";

test("synchronous passing test", (t) => {
  assert.strictEqual(1, 1);
});

// Native WebSocket
const ws = new WebSocket("ws://example.com/socket");
ws.onopen = () => console.log("Connected");

Core Concepts

Modern Native HTTP Server & Fetch

Zero-dependency HTTP server utilizing Node.js modern standard APIs:

import { createServer } from "node:http";

const server = createServer(async (req, res) => {
  const url = new URL(req.url, `http://${req.headers.host}`);

  if (url.pathname === "/api/health" && req.method === "GET") {
    res.writeHead(200, { "Content-Type": "application/json" });
    res.end(JSON.stringify({ status: "ok", nodeVersion: process.version }));
    return;
  }

  res.writeHead(404, { "Content-Type": "application/json" });
  res.end(JSON.stringify({ error: "Route not found" }));
});

server.listen(3000, () => {
  console.log("Node.js server listening on http://localhost:3000");
});

Stream Pipelines with node:stream/promises

Safe, backpressure-managed file and network streaming:

import { createReadStream, createWriteStream } from "node:fs";
import { pipeline } from "node:stream/promises";
import { createGzip } from "node:zlib";

async function compressFile(sourcePath, destPath) {
  try {
    await pipeline(
      createReadStream(sourcePath),
      createGzip(),
      createWriteStream(destPath),
    );
    console.log(`Successfully compressed ${sourcePath} -> ${destPath}`);
  } catch (err) {
    console.error("Pipeline compression failed:", err);
  }
}

Native Test Runner with node:test

Fast, zero-dependency testing built directly into the runtime:

import test, { describe, it } from "node:test";
import assert from "node:assert/strict";

describe("User Authentication", () => {
  it("validates password minimum length", () => {
    const password = "supersecretpass";
    assert.ok(password.length >= 8, "Password must be >= 8 chars");
  });

  it("verifies async promise resolution", async () => {
    const token = await Promise.resolve("jwt-token-xyz");
    assert.equal(token, "jwt-token-xyz");
  });
});

Common Patterns

High-Throughput Stream Pipeline with Backpressure

Problem: Reading large files directly into memory with fs.readFile causes OOM crashes under load.

Solution: Use stream.pipeline for automatic backpressure management:

import { pipeline } from "node:stream/promises";
import fs from "node:fs";
import zlib from "node:zlib";

async function compressLogFile(inputPath, outputPath) {
  await pipeline(
    fs.createReadStream(inputPath),
    zlib.createGzip(),
    fs.createWriteStream(outputPath),
  );
  console.log("Compression pipeline completed successfully.");
}

Best Practices

Do:

  • Target Node.js 22 LTS or newer with native fetch, web streams, and native test runner.
  • Use the node: protocol prefix (import fs from 'node:fs') for all built-in modules.
  • Use node:stream/promises and pipeline to handle stream backpressure and error propagation.
  • Handle uncaught exceptions (process.on('uncaughtException')) and trigger graceful shutdown.

Don't:

  • Block the single-threaded Event Loop with heavy synchronous calls (fs.readFileSync, long regex).
  • Use CommonJS (require()) in greenfield applications; adopt ECMAScript Modules ("type": "module").
  • Ignore unhandled promise rejections; configure --unhandled-rejections=strict.

Troubleshooting

ErrorCauseSolution
ERR_REQUIRE_ESM: Must use import to load ES ModuleUsing require() on a modern ESM-only package.Use import or dynamic await import('...') in CommonJS.
MaxListenersExceededWarning: Possible EventEmitter memory leakAdding event listeners in loop without removing them.Remove listeners with emitter.off() or increase limit using emitter.setMaxListeners(n).
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failedNode.js process exceeded default 1.4GB memory limit.Start with expanded heap: node --max-old-space-size=4096 app.js.

References

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.