How to use ESM modules in Node.js
Wednesday, February 25, 2026
Node.js traditionally used CommonJS modules with require() and module.exports, but modern JavaScript uses ES modules with import and export syntax.
With over 10 years of experience building Node.js applications and as the creator of CoreUI, I’ve migrated numerous projects from CommonJS to ES modules to leverage modern JavaScript features.
From my expertise, the most straightforward approach is to add "type": "module" to your package.json, which enables ESM by default for all .js files.
This method aligns your Node.js code with browser JavaScript and modern tooling.