Node.js ESM Basics
Node v10 reaches its official end of life on April 30th, 2021. That matters because it means every supported Node.js release now includes native EcmaScript Modules support. ESM is the future of the Node ecosystem, even if there are mixed feelings about moving away from CommonJS.
To get started, you need a JavaScript file to run. Next, create a second file that imports and executes the first one. Try running it and you will hit a snag: Node.js can't break its module system, so ESM is strictly opt-in.
You have two ways to opt in. Rename a single file from .js to .mjs, or opt in an entire directory by adding a package.json with "type": "module". The second option avoids renaming every file.
{
"type": "module"
}
Now run the script again and it works. That is all it takes to get native ESM running in Node.js.



