SuperAPI AI Directory

node

Coding & development

View repository

Updated 10-16 10:21

About this skill

Node.js

Covers the Node runtime + the JS already stable in that V8. The type system is left to the TypeScript skill; Vue / build tools are not covered.

Do not write APIs from training data. First determine the even major (check the minor too if necessary), then read the corresponding reference.

Determine the version

Read in this orderthe actually locked/installedversion, do not just look at package.json of engines.node range (^ / >=):

  1. node -v
  2. .nvmrc / .node-version
  3. Volta(package.json of volta.node)
  4. package.json of engines.node(use only as a last resort)

Take even major(v24.14.0 → 24). For odd majors round down to the even one:23 → 22,25 → 24. Open the file in the table below,only use the sections in that file that are ≤ the current minor。

major File
22 references/22.md
24 references/24.md
26 references/26.md

For newer even majors not listed: use 26 as the base, then check the official changelog / API History for that major. For older ones: do not use the new APIs in this skill.

When writing code, open only the current tier, do not blindly read the whole folder. When the current version is already 26, the start of the 26 tier has a short index of what 22/24 should still use.

Baseline (22+)

  • For new code prefer ESM(package.json "type": "module", or .mjs). For CJS interop follow the require(esm) rules of the current tier, do not add another build layer for interop.
  • Prefer built-ins:node:fs / node:path / node:http / node:test / node:sqlite etc. always carry the node: prefix.
  • Web standards are already in the runtime: use the global fetch、WebSocket(stable since 22.4), do not install node-fetch / ws again for the client.
  • For dev restart use node --watch, do not add nodemon for this.
  • For JSON modules use import attributes:with { type: 'json' }. Do not assert { type: 'json' }(import assertions were removed in 22.0).
  • Testing: if the project has no Jest/Vitest use node:test + node --test. If it does, follow the project.
  • When the current tier allows running .ts directly, Node only strips types, does not type-check. Type checking goes through tsc / the TypeScript skill.
import { readFile } from 'node:fs/promises'
import { test } from 'node:test'
import assert from 'node:assert/strict'

const res = await fetch('https://example.com')
const ws = new WebSocket('wss://example.com')

Do not:

import fetch from 'node-fetch'
import WebSocket from 'ws'
const fs = require('fs') // 新代码不要省略 node: