Categories
JavaScript Answers

How to use ES6 modules in Node 12?

Spread the love

To use ES6 modules in Node 12, we set the --experimental-modules option.

For instance, we write

{
  "scripts": {
    "start": "node --experimental-modules src/index.mjs "
  }
}

in package.json to add the start script.

We use it to run node with the --experimental-modules on to enable ES6 modules support.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *