Fork me on GitHub Fork me on GitHub

require()


<%
var core = require("core");
var log = new core.Log();
log.info("Required the module");
 
function myFunc() {
    var ws = require("ws");
    var client = new ws.WSRequest();
    log.info("Required within a function");
}
%>

Overview

In-built function require() allows to get a reference for any available Jaggery module. Adding a Jaggery module is detailed here. Apart from Jaggery modules, require() can import javascript(*.js) or JSON(*.json) files and assign it to a variable.

var module = require("module_name");
var js = require("foo.js");
var json = require("bar.json");


Parameters

Parameter Type Description
module_nameString
var module = require("module_name");
The module name which is specified in the modules.xml
{scriptfile}.jsString
var js = require("foo.js");
Path of the script that need to be imported
{jsonfile}.jsonString
var json = require("bar.json");
Path of the JSON file that need to be imported

Return values

Value Type Description
module_nameObject
var module = require("module_name");
the Module as a javascript object
{scriptfile}.jsObject
var js = require("foo.js");
The imported script as a javascript object
{jsonfile}.jsonObject
var json = require("bar.json");
The imported JSON as a javascript object