Skip to content

require()

Description

The require() function is used to load a module. Unlike the include() function, which loads a file and returns it as a string, the require() function returns an object that contains the exported data from the loaded file.

Syntax

JS
require(path: String) -> Object

Parameters

Parameter Type Description
path String The path to the script file that needs to be loaded.

Path Types

Type of Path Example Description
Absolute "C:/scripts/library.js" The full path to a file on disk.
Relative "../config/settings.js" A path relative to the current executing file.

File Extension Support

You can omit the .js file extension when specifying the path. For example, require("utils") automatically finds the file utils.js.

Return value

Type Description
Object If the file does not have explicit exports, an empty object ({}) is returned.

Example

JS
1
2
3
4
let path = "./helpers";
let helpers = require(path);

let library = require("C:/scripts/library");

See also

include()

Last update: 14 August 2025, 18:47