require
Load a CommonJS module or JSON file.
js
require(specifier)Arguments
| Argument | Type | Meaning |
|---|---|---|
specifier | string | Relative to the importing module, absolute path, built-in adapter, or installed CommonJS package. |
Returns
module.exports or parsed JSON. Throws on resolution/format errors.
Example
js
// main.js
const {greet} = require("./helpers/greet");
console.log(greet("Sam"));
// helpers/greet.js
// exports.greet = name => "Hello " + name;Notes
Supports .js/.cjs, JSON, directory index and package.json main. No automatic npm install, ES modules, Node built-ins or native addons. Every module resolves its own ./ paths.