Skip to content

Requiring modules

Clarive JS has a require module system that allows users to require internal and external modules.

Internal Cla Modules

Internal modules are prefixed with cla/:

const db = require('cla/db');

Standard Modules

Standard modules are the ones shipped with Clarive under CLARIVE_HOME/plugins/cla_modules.

Only a few usable modules are located there, as they are used internally by Clarive JS processes.

Some modules currently available:

const _ = require('underscore');
const hs = require('handlebars');

Plugin Modules

Here's where users can call modules defined either in:

1) plugins downloaded from the Clarive Plugins page

2) plugins created ad-hoc by the user

Either way, external plugin modules will go into your CLARIVE_BASE/plugins installation directory, which could be /opt/clarive/plugins for example.

Creating User-defined plugin modules

1) Create a plugin, say myplugin, under CLARIVE_BASE/plugins, read here for more instructions

2) Add a modules folder under your plugin, ie. CLARIVE_BASE/plugins/modules

3) Create a module file, which can be either in plain ES5 JS (.js), ES6/Babel (.es6) or Typescript (.ts) under the modules folder.

Example CLARIVE_BASE/plugins/modules/mylib.ts:

export const mySum = (a,b) => {
    return a + b;

export const myMul = (a,b) => {
    return a * b;

Then call it from any other place in the Clarive JS space:

const myfuncs = require('/myplugin/mylib.ts');
myfuncs.mySum(2,3);  // returns 5