Skip to main content

Using user JS Modules

YepCode JS Modules allow to define an isolated set of JavaScript functions to be reused from any of your process.

These modules may help to share functions between processes to solve some business logic problem, to encapsulate access to some service, or any other purpose where splitting the code in modules makes sense.

To use a JS Module you need to write yepcode.import sentence in the line you want to use it. For example: const { myFunc } = yepcode.import('js-module'). It can be used in any process code or in other JS Module.

You can have as much js modules as you need, and all of them work like any CommonJS module, exporting the functions that you want to use from processes source code.

A sample of js module exporting only one function to say hello:

module.exports = () => console.log("Hello world!");

If you need to use this library from a YepCode process, and it has a name say_hello, the piece of code to do that would be:

const sayHello = yepcode.import("say_hello");


A module may also export several functions:

const sayHelloToMike = () => console.log("Hello Mike!");
const sayHelloToDavid = () => console.log("Hello David!");

module.exports = { sayHelloToMike, sayHelloToDavid };

To use that functions, you have to read it from the returned object:

const sayHelloModule = yepcode.import("say_hello");


Writing JS modules from process edition screen

You can easily view and change JS modules from the process edition page, opening a component with this shortcut:

With that, a modal window shows you the defined modules, making easy to modify or consult them.