Nodeschnaps is a node.js compatibility layer for Java Javscript engines like Rhino. The main inspiration is to run ETL transformation with the same code we use in node.js to save development time.
We work hard to implement the full API of node.js. So you could load Nodeschnaps into your Rhino environment and use your node.js code without restrictions. Take a look at the current development status to get a overview of what we done so far.
- Rhino JS
- Pentaho Data-Integration (Kettle)
- Nashorn
- Pentaho Data-Integration (Kettle)
npm install nodeschnaps
Install dev dependencies:
npm install
Run tests with rhinojs:
make test
Run tests with nodejs:
make testNode
(required)
Path to search for modules/files (Last must be the nodeschnaps lib folder).
One path of the variable must be set to the lib folder of nodeschnaps. The path separator is like in the other path variables ":".
Nodeschnaps need to know his location to load his own modules.
The paths should be absolute to be independent from applications CWD like in the case of Kettle.
Example:
/home/you/project/node_modules:/home/you/project/node_modules/nodeschnaps/lib
(optional)
A path to a module, what will be loaded at the start to modify the environment.
To load nodeschnaps the environment variable NODESCHNAPS_PATH must be set.
Optional you can use for rhino the includet rhino jar in the deps/rhino/lib folder.
Example for rhino:
java \
-cp ./node_modules/nodeschnaps/deps/rhino/lib/rhino-1.7.11.jar \
-DNODESCHNAPS_PATH=/home/you/project/node_modules/nodeschnaps/lib \
org.mozilla.javascript.tools.shell.Main \
test.js
load('./node_modules/nodeschnaps/loader.js');
// Your code here ...
NodeJS();
Start Script
LoadScriptFile(getEnvironmentVar('NODESCHNAPS_LOADER_FILE'));
// Your code here ...
NodeJS();
Transform Script
// Your code here ...
NodeJS();
End Script
// Your code here ...
NodeJS();
new Function(
org.apache.commons.io.FileUtils.readFileToString(
new java.io.File(parent_job.getVariable('NODESCHNAPS_LOADER_FILE'))
)
)();
// Your code here ...
NodeJS();
For a example look at: kitchen-stove
java \
-DNODESCHNAPS_PATH=./node_modules/nodeschnaps/lib \
-cp ./node_modules/nodeschnaps/deps/rhino/lib/rhino-1.7.11.jar \
org.mozilla.javascript.tools.shell.Main \
YOUR.js
jjs \
--language=es5 \
-DNODESCHNAPS_PATH=./node_modules/nodeschnaps/lib \
YOUR.js
As callback:
NodeJS(function(){
// Your code here ...
});
Or before:
// Your code here ...
NodeJS();