TestingDocs.com logoTestingDocs.com
Automation learning lab
TestingDocs • Self-paced course

Playwright Automation
Self Study Guide

Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.

60 chaptersBeginner friendlyHands-on practice
JavaScript / Chapter 17 of 60~12 min • Beginner
Chapter 17JavaScript

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

  1. Save math.mjs
  2. Save main.mjs with an import
  3. Run node main.mjs

Example

JavaScript
// math.mjs
export const add = (a, b) => a + b;

// main.mjs
import { add } from './math.mjs';
console.log(add(2, 3));
Expected result: 5
💡 Point to remember
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