Node.js Reference ยท Concepts and Pitfalls
Modern Node.js features
A tour of the built-in Node.js features that replace common packages: fetch, the test runner, watch mode, .env files, TypeScript, node:sqlite and more.
Node.js used to be a small core surrounded by a huge package ecosystem: you installed a library for HTTP requests, another for tests, another for file watching and another for reading .env files. Over the last releases much of that moved into Node itself. Recent LTS versions give you a web-standard fetch(), a test runner, a watch mode, .env loading, TypeScript type stripping, an embedded SQLite database and a stable permission and diagnostics toolbox.
This page is a map, not a manual. Each section shows the feature working and points to its own reference page. Always check the version notes: some features are stable in Node.js 24, others are still marked experimental or release candidates, and flags change between versions.
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.
What is built in
| Need | Modern built-in | Reference |
|---|---|---|
| HTTP requests | fetch(), Request, Response |
fetch() |
| Cancellation and timeouts | AbortController, AbortSignal.timeout() |
AbortSignal |
| Deep copy | structuredClone() |
structuredClone() |
| Testing | node:test, node:assert, mock |
test() |
| Run on change | node --watch |
see below |
| Environment files | --env-file, process.loadEnvFile() |
--env-file |
| Argument parsing | util.parseArgs() |
util.parseArgs() |
| TypeScript | type stripping | --experimental-strip-types |
| Embedded database | node:sqlite |
DatabaseSync |
| Test coverage | --experimental-test-coverage |
Test coverage |
ES modules and import() |
native, plus require(esm) |
require(esm) |
Commands you will use
Several of these are command-line features, so they are shown read-only here.
node --watch server.js # restart when the entry file or its imports change node --test # find and run test files node --test --watch # re-run tests on change node --env-file=.env app.js # load variables before the program starts node app.ts # run TypeScript (type syntax is stripped, not checked)
--watch restarts the whole process, so it suits servers and scripts; it replaces the old habit of installing a file-watcher package for development. For watching files from inside a program, use fs.watch().
Usage notes
- Type stripping is not type checking. Node removes type annotations and runs the rest; it never reports a type error. Run
tsc --noEmit(or your editor) for checking. Constructs that need code generation, such as enums and parameter properties, need extra flags or must be avoided. Seemodule.stripTypeScriptTypes(). - Imports need real extensions. In ES modules,
import './util.ts'must name the file exactly, which is why TypeScript projects for Node write the.tsextension. See Module file extensions. fetch()is not a replacement for everything. It follows redirects and has no raw-socket control; compare it withhttp.request()in fetch versus http.request.node:testreplaces a lot, not all. It has suites, hooks, mocks, snapshots and coverage, but plugin ecosystems of other runners (custom matchers, browser testing) still exist.- The prefix matters for built-ins. Write
node:fs,node:sqliteand so on. Some newer modules, includingnode:sqliteandnode:test, are only available with thenode:prefix. - Stability varies. The docs label each API Stable, Experimental or similar. Experimental features can print a warning and may change in a minor release, so pin your Node version and read release notes before depending on them in production.
- Prefer built-ins for small jobs, packages for big ones. A weekend script benefits from zero installs; an application needing a full ORM or a mature test matcher library may still choose a package.
- Check the runtime version in code with
process.versionorprocess.versions.nodewhen a feature is newer than your minimum supported Node.