Page History
...
Users can install Node.js 3rd-party packages in the JS7 Agent's data directory like thisany location, preferably in the Oracle® GraalVM's ./bin directory. Consider to use a current version of the Oracle® GraalVM:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
# set location of GraalVM JAVA_HOME=/opt/java/graalvm-community-openjdk-17.0.7+7.1 PACKAGE_HOME=/var/sos-berlin.com/js7/agent/node_modules # install Node.js packages # installed packages by default will be located in $JAVA_HOME/bin/node_modules sub-directory # it is recommended to use the --prefix argument to specify a location in the Agent's data directory $JAVA_HOME/bin/npm install --prefix $PACKAGE_HOME -g url $JAVA_HOME/bin/npm install --prefix $PACKAGE_HOME -g http $JAVA_HOME/bin/npm install --prefix $PACKAGE_HOME -g Buffer $JAVA_HOME/bin/npm install url $JAVA_HOME/bin/npm install Buffer |
Configuration
By default the Oracle® GraalVM does not allow to load 3rd-party packages using the require() function. Users who wish to add such packages to their JavaScript jobs can create a JS7 - Job Resource that holds the required configuration items.
In the Configuration->Inventory view navigate to the folder that should store the Job Resource.
- The Job Resource can be assigned an arbitrary name.
- The Job Resource holds a single argument with the name
js7_options.graalvm.js
(required): - Users can click the icon in the value input field to open the editor:
.
As a value to the Job Resource argument a number of options for Oracle® GraalVM can be added like this:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
toFile('
{
"options": {
"js.commonjs-require": true,
"js.commonjs-require-cwd": "/opt/java/graalvm-community-openjdk-17.0.7+7.1/bin/node_modules",
"js.commonjs-core-modules-replacements": ""
}
}','*.json') |
Explanation:
toFile
: the JS7 toFile() function takes two arguments:- the string that holds the Oracle® GraalVM options in JSON format,
- the file name extension *.json. A file with this extension will be created in the JS7 Agent's
<data>/work
directory and will be used when executing JavaScript jobs.
- Options
js.commonjs-require
: Is required to hold the valuetrue
in order to enable use of 3rd-party packages.js.commonjs-require-cwd
: Specifies the path to thenode_modules
directory that holds 3rd-party packages.js.commonjs-core-modules-replacements
: Optionally can be used to map built-in Node.js modules to 3rd-party packages. The syntax<node-built-in-module>:<3rd-party-package>[,<node-built-in-module>:<3rd-party-package>]
can be used.- For details see https://www.graalvm.org/latest/reference-manual/js/Modules/