Use functions defined in other JavaScript files
- Last Updated: April 5, 2023
- 1 minute read
- Corticon.js
- Documentation
You can use a library or functions defined in supporting JavaScript files by creating a
file that defines the function, and then using the function from a
require statement.
Example of a utility function
CODE: CallToSeparateLibrary/Util.js
This example determines the appropriate greeting based on the time of day.
|
The last line exposes the function publicly.
Example of referencing the utility function
With the function defined, the require call brings the function into
the service callout, and then exports the result, as follows:
CODE: HelloWorldServiceCallout.js
|
Note: Only Node module usage is supported where you
can use
require and module.exports. Modules written
with ES6 import/export are not supported.