Node.js has included experimental support for ES6 support. Read more about here: https://nodejs.org/docs/latest-v13.x/api/esm.html#esm_enabling.
TLDR;
Node.js >= v13
It's very simple in Node.js 13 and above. You need to either:
.mjs
extension, or{ "type": "module" }
in the nearest package.json
.You only need to do one of the above to be able to use ECMAScript modules.
Node.js <= v12
If you are using Node.js version 8-12, save the file with ES6 modules with .mjs
extension and run it like:
node --experimental-modules my-app.mjs