Chapter 17: Modules, import and export
Automation learning lab
Playwright Automation
Self Study Guide
Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.
Modules, import and export
Modules split code across files and make dependencies explicit. Node supports ECMAScript modules through .mjs files or a suitable package.json type setting. Named exports are imported using braces. Playwright test files commonly use import syntax.
How it works
Step-by-step walkthrough
- Save math.mjs
- Save main.mjs with an import
- Run node main.mjs
Example
// math.mjs
export const add = (a, b) => a + b;
// main.mjs
import { add } from './math.mjs';
console.log(add(2, 3));Use the correct relative path and file extension for native Node ESM.
✎ Your practice task
Export a subtract function in math.mjs.
Knowledge check
Which keyword exposes a named module member?
🌐 Continue learning
60-chapter learning path
Start at chapter 1, or choose any topic. Your progress is tracked separately for each chapter.
JavaScript fundamentals
TypeScript fundamentals
Playwright • setup & locators
Playwright • interactions & assertions
Playwright • framework & debugging
Playwright • real-world automation
Interactive practice lab
Try the controls below and observe the corresponding Playwright locator instructions. This browser demo does not execute Node.js or Playwright Test; copy the code to your local Playwright project to automate it.
Task manager demo
Suggested automation
Actions on the demo update these examples. In your local test use a page that contains the same controls.
Download a standalone lab page, then serve it locally (for example with Python's http.server). Navigate to it in a Playwright test.