Set the Node.js Project to ECMAScript Modules (ESM)

Share this video with your friends

Send Tweet

Node.js projects have two ways that you can import and export code into different files. This is through CommonJS (CJS) and ECMAScript modules (ESM).

CommonJS is Node's default way to import modules but because I like to have my Node.js code similar to my frontend code, we will use ESM for this project.

To do so we will set a project type in our package.json.