Skip to content

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.

0 0 votes
Article Rating
Notify of

1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments