JavaScript 2025 cheatsheet

JavaScript 2025: Modules

5 common JavaScript 2025 tasks.

Export and import by name

Share functions between files with ES modules.

// math.js
export function add(a, b) {
  return a + b;
}

// app.js
import { add } from "./math.js";

Default export

Export one main value per file.

// logger.js
export default function log(message) {
  console.log(message);
}

// app.js
import log from "./logger.js";

Load a module on demand

Import code only when it is needed.

const { Chart } = await import("./chart.js");

Load a module in HTML

Modules are deferred and run in strict mode automatically.

<script type="module" src="/app.js"></script>

Import a Node.js built-in

Use the node: prefix for built-in modules.

import { readFile } from "node:fs/promises";

const text = await readFile("data.txt", "utf8");

Was this page helpful?