Skip to content

Writing import modules with NodeJS

Here's an example of a NodeJS import module that could serve as an skeleton.

#!/usr/bin/env node


process.stdin.once('data', function (input) {

    input = JSON.parse( input );

    console.log({ [process.env.CLARIVE_RETURN]: { 'hello': input.quux } });


Don't forget to apply the execute flag +x to your import modules. Clarive rules can only invoke modules that are executable. Make sure that the shebang #! definition points to a valid binary in the docker container image that will be used with your module.

To test the above NodeJS import module from the command line, try the following command:

echo '{ "quux": 123 }' | CLARIVE_RETURN=1234 ./node_hello.js

If everything went well, the following output should be shown.

{"1234": { "hello": 123 } }

Using NodeJS imports in your rulebook

To use a NodeJS module you have to first check it into a Git repository managed by Clarive.

Let's suppose there is a project called MyProject set up in your system, and that the project has a Git repository called MyRepo. Therefore the path to your rulebook and module would be:


Now in your rulebook import the NodeJS file with the import: directive. You can try this using the the REPL.

image: node
   - MyProject/MyRepo
   - /MyProject/MyRepo/.clarive/imports
   - echo: "and now for something completely different:"
   - node_hello:
        quux: "world"