- The ESM syntax is
import {x} from 'module'
-
To be able to use this syntax in Nodejs, we have several ways:
- Rename the file to .mjs
- Create package.json file and add: {“type”:”module”}
- Install this esm module:
npm i -g esm
For the last choice, run node
node -r esm ES-module-file.js