Full Stack LAMP - MEAN Developer, Python developer. Certified Azure Developer. Freelance programmer/consultant/trainer.

How to Use ECMAScript Modules in Node.js

In this post, you’ll learn how to enable and use ES modules in Node.js. Starting version 13.2.0, Node.js has stable support for ES modules. The ECMAScript modules (in short ES modules) is a JavaScript modules format that uses import and export statements.

By default .js files in Node.js are considered CommonJS modules. To make .js files as ES modules simply set "type" field as "module" in the package.json, { “type”: “module” }

Or You can create files with the .mjs file extension. Node.js treats the .mjs file extension files as ECMAScript modules.

Leave a Reply