Importing function from another node

I have a similar solution that I often use, calling it the "module pattern". I keep my shared modules on the very first tab, triggered by a trigger node ('Inject once after...' option), so they get initialized first and put into global context.

image

The "module" (an example):

const util = (function () {
    'use strict';
    
    function add(a, b) {
        return a + b;
    }
    
    return {
        add: add
    };
    
}());

global.set('util', util);

It is wrapped in an IIFE so I can use strict mode, something you can't do in the function node itself.

In your function nodes you can use it the same way as yours, but with the benefit of having the code editable in the runtime, no restart required.

2 Likes