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_name | String |
var module = require("module_name"); The module name which is specified in the modules.xml |
{scriptfile}.js | String |
var js = require("foo.js"); Path of the script that need to be imported |
{jsonfile}.json | String |
var json = require("bar.json"); Path of the JSON file that need to be imported |
Return values
Value |
Type |
Description |
module_name | Object |
var module = require("module_name"); the Module as a javascript object |
{scriptfile}.js | Object |
var js = require("foo.js"); The imported script as a javascript object |
{jsonfile}.json | Object |
var json = require("bar.json"); The imported JSON as a javascript object |