Modules
require()
CommonJS loader that resolves the supplied module identifier and returns the loaded export. Use explicit node: specifiers for built-ins and relative paths for local modules. Loading executes module initialization; only load trusted code.
Formal Syntax & Structure
nodejs syntaxnodejs
require(id)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| id | string | Built-in, local file or package identifier. |
Return Value
any
Exported value of the resolved module; ESM interoperability depends on runtime and graph.
Working Example
Example Snippetnodejs
const assert = require("node:assert/strict");console.log(typeof assert.equal);