CommonJS vs ES Modules in Node.js — a practical guide to CommonJS vs ESM with clear examples you can reuse in real projects.
CommonJS vs ES Modules in Node.js — 28/55 in the Node.js series. Full playlist companion: Node.js complete course on YouTube. Prefer one article? Read the complete Node.js tutorial.
Short description
CommonJS (`require`) is classic Node style. ES Modules (`import`/`export`) are the modern standard — enable with `"type": "module"` in package.json.
Both styles
// CommonJS
const fs = require('fs');
module.exports = { ok: true };
// ESM (package.json: "type": "module")
import fs from 'fs';
export const ok = true;