Next.js starter your AI actually understands. Ship internal tools in days not weeks. Pre-order $199 $499 → [Get it now]

How to use ESM modules in Node.js

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.

Read More…