Share this page

# lr.require

Loads the specified JavaScript module.

Runtime Functions

## Syntax

                lr.require( "<path>" );

Argument | Comments
--- | ---
path | One of: A file name - The file is in the script folder. ("myscript.js") A relative path - The path root is the script folder. ("../../myscript.js") A fully specified path name. ("C:\scripts\myscript.js") The directory containing the module. For example: "modules", "../../modules", "C:\modules". If there is a package.json in the folder that contains a `main` module value, the main module is loaded. Otherwise, index.js is loaded.

The lr.require function loads the specified JavaScript module. Enter the function manually before the beginning of the action scope.

## Return Values

An object containing the members exported from the library.

## Parameterization

Parameterization is not applicable to this function.

## Example

### Contents of shapes.js

var circle = lr.require('circle.js')

var square = lr.require('square.js')

exports.circle = circle;

exports.square = square;

### Contents of circle.js

var PI = Math.PI;

exports.area = function (r) { return PI * r * r; };

exports.circumference = function (r) { return 2 * PI * r; };

### Contents of square.js

exports.area = function (w) { return w * w; };

exports.circumference = function (w) { return 4 * w; };

### Contents of Lib2/package.json

{ "name" : "shapes",

"main" : "shapes.js" }

### Example of usage in script

Copy code

    var lib1 = lr.require('Lib1/shapes.js');
    var lib2 = lr.require('Lib2');
    function Action()
    {
    // Calculate the area of a square of width 5
    lr.outputMessage(lib1.square.area(5));
    // Calculate the area of a circle of radius 5
    lr.outputMessage(lib1.circle.area(5));

    // Calculate the area of a square of width 5
    lr.outputMessage(lib2.square.area(5));
    // Calculate the area of a circle of radius 5
    lr.outputMessage(lib2.circle.area(5));

    return 0;
    }

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: