ES Modules
Use ES Modules (import/export) in Node.js, migrate from CommonJS, and handle common module issues.

Join the AI Workshop to learn more about AI and how it can be applied to web development. Next cohort February 1st, 2026

The AI-first Web Development BOOTCAMP cohort starts February 24th, 2026. 10 weeks of intensive training and hands-on projects.


ES Modules (ESM) are the standard module system in JavaScript, using import and export syntax. Node.js originally used CommonJS modules, but now fully supports ES Modules, and understanding both systems is important for modern Node.js development.

In this unit, you’ll learn how to use ES Modules in Node.js. We’ll cover the import/export syntax, configuring your project for ESM, migrating from CommonJS, and handling common module-related issues you might encounter.

Understanding ES Modules is essential for writing modern Node.js code and for working with the many npm packages that now ship as ES Modules.

Lessons in this unit:

0: ▶︎ Introduction
1: How to fix "cannot use import statement outside a module"
2: How to fix "__dirname is not defined in ES module scope"
3: How to fix the error "unexpected token "{". import call expects exactly one argument"
4: How to enable ES Modules in Node.js
5: How to use .env files in Node.js with import syntax
6: How to use import in Node.js
7: Expose functionality from a Node file using exports