I have a JavaScript policy that needs to require a Node.js module assert. The JavaScript file testAssert.js has the following code:
var assert = require('assert');
var transactionId = context.getVariable("transactionId");
var result = assert.equals(transactionId, "123");
print("test assert:" + result);
The following is the policy that invokes the JavaScript file:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Javascript async="false" continueOnError="false" enabled="true" timeLimit="200" name="retrievePointsHistory">
<DisplayName>retrievePointsHistory</DisplayName>
<Properties/>
<ResourceURL>jsc://testAssert.js</ResourceURL>
</Javascript>
It throws the following exception:
{
"fault": {
"faultstring": "Execution of retrievePointsHistory failed with error: Javascript runtime error: \"ReferenceError: \"require\" is not defined. (retrievePointsHistory.js:1)\"",
"detail": {
"errorcode": "steps.javascript.ScriptExecutionFailed"
}
}
}
It seems that a JavaScript policy cannot use "require". Any help is appreciated.