Modules

import()

Asynchronously loads a module and resolves to its namespace. Use reviewed fixed specifiers. The expression is supported in both ESM and CommonJS; the target and runtime determine resolution behavior.

Formal Syntax & Structure

nodejs syntaxnodejs
import(specifier)

Parameters & Attributes

NameTypeDescription
specifierstringSpecifier of the module to import.

Return Value

Promise<module namespace>

Fulfills with the loaded namespace or rejects on loading/evaluation failure.

Working Example

Example Snippetnodejs
const path = await import("node:path");console.log(path.posix.join("books", "7"));
Node.js Reference