Skip to main content

Using User Modules

YepCode Modules allow you to define an isolated set of JavaScript or Python functions for reuse in any of your processes. These modules are designed to help share functions across processes, solve business logic problems, encapsulate access to services, and more.

Modules function slightly differently in JavaScript and Python. Here's a guide for both:

To use a module, use the custom import syntax in the process (or other module) where you want to utilize it.

const { myFunc } = yepcode.import("your-module");
tip

Modules also support versioning, and if you want to import one specific module version, just add a second parameter to the import sentence:

const { myFunc } = yepcode.import("your-module", "v1.0");

You can have as many modules as needed, and they work like any CommonJS module, exporting the functions you want to use from process source code.

For example, a JavaScript module exporting a function to say hello:

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

To use this library from a YepCode process named say_hello, the code would be:

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

sayHello();

A module can also export several functions:

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

module.exports = { sayHelloToMike, sayHelloToDavid };

To use these functions, read them from the returned object:

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

sayHelloModule.sayHelloToMike();
sayHelloModule.sayHelloToDavid();

Writing Modules from Process Edition Screen

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

A modal window then shows you the defined modules, making it easy to modify or consult them.