Modern Node.js: Built-in Features That Replace npm Packages
If you learned Node.js a few years ago, you probably install packages for things the runtime now does itself. Here's a tour of built-ins in current LTS versions.
fetch, WebSocket and Web APIs
const res = await fetch('https://api.github.com/repos/nodejs/node');
const repo = await res.json();
const ac = AbortSignal.timeout(5000); // cancel slow requests
await fetch(url, { signal: ac });
fetch, Response, FormData, structuredClone, crypto.randomUUID() and a global WebSocket client are all built in.
Watch mode instead of nodemon
node --watch src/server.js
.env files instead of dotenv
node --env-file=.env src/server.js
A test runner instead of Jest/Mocha
import { test } from 'node:test';
import assert from 'node:assert/strict';
test('adds numbers', () => {
assert.equal(1 + 1, 2);
});
node --test
Run TypeScript directly
Recent versions strip TypeScript types, so node app.ts works for code that uses only erasable syntax (no enums). Type-check separately with tsc --noEmit.
More worth knowing
node:sqlite- an embedded SQLite database module (still marked experimental).require()of ES modules - CommonJS code can load synchronous ESM packages.--permission- restrict file system, child process and worker access for a script.util.parseArgs- command-line argument parsing for small CLIs.util.styleText- coloured terminal output without chalk.
Run an Active LTS version in production and check the release notes when you upgrade; many "experimental" features become stable within a year.
Was this article helpful?
Comments
No comments yet. Have a question or a tip? Be the first to share it.