Built-in APIs Basics
8 examples to get you started with Node built-in APIs - 6 basic and 2 intermediate.
Search across all documentation pages
8 examples to get you started with Node built-in APIs - 6 basic and 2 intermediate.
import from 'node:…' in ESM projects.Import built-ins explicitly and avoid shadowing.
import { readFile } from 'node:fs/promises';
import { createServer } from 'node:http';
import path from 'node:path';node: prefix is optional but recommended in application code.package.json dependencies.@types/node in devDependencies.Async file read without util.promisify.
import { readFile } from 'node:fs/promises';
const pkg = JSON.parse(await readFile('package.json', 'utf8'));
console.log(pkg.name);createReadStream for large files.ENOENT with try/catch for optional config files.Related: fs and fs/promises - streams and flags
Portable paths in ESM without __dirname.
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __filename = fileURLToPath(import.meta.url);
const configPath = path.join(path.dirname(__filename), 'config.json');path.join normalizes separators for the platform./ manually in library code.path.posix.join for object storage keys on all platforms.Related: path and url - URL vs path
Minimal HTTP without Express.
import { createServer } from 'node:http';
createServer((req, res) => {
res.writeHead(200, { 'content-type': 'text/plain' });
res.end('ok');
}).listen(3000);server.requestTimeout) in Node 24.Identifiers without uuid package.
import { randomUUID } from 'node:crypto';
const id = randomUUID();
console.log(id);randomBytes for tokens - encode as base64url.Promise-based delay without npm.
import { setTimeout } from 'node:timers/promises';
await setTimeout(100);
console.log('after delay');AbortSignal for cancellable delays.setInterval still callback-based for periodic work.HTTP client without axios for simple outbound calls.
const res = await fetch('https://nodejs.org/dist/index.json');
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();fetch in Node 24 - same API as browsers.Modern utilities for env and CLI output.
import { parseEnv } from 'node:util';
import { styleText } from 'node:util';
const env = parseEnv('PORT=3000\nNODE_ENV=production');
console.log(styleText('green', 'boot'), env.PORT);parseEnv parses dotenv-style strings in memory.Related: Zod at Boundaries - validate env
Stack versions: This page was written for Node.js 24.18.0 (Active LTS), npm 10+, TypeScript 5.6+, Express 5, Fastify 5, and NestJS 11.
Reviewed by Chris St. John·Last updated Jul 16, 2026