hi, I have functions in javascript file that I want to use in some of my workflows, how can I call the function inside my file without putting another node for it?
I know the I can make require to the file and then call to one of the function, is this the best way?
Hi @Asaf_Shay, you could put your custom code in a single workflow and then call this one âcustom code workflowâ from all other workflows through the Execute Workflow node.
I have the custom module
module.exports = {
foo: function () {
// whatever
return âaaaâ;
},
bar: function () {
// whatever
return âbbbbâ
}
};
I save the file as common.js
when I try to:
var common = require(common.js);
I get the common module not found
where should I put the file ?
Iâm facing the same issue. I have a file saved under /data/mytest.js and Iâve tried to import it in a Function node with const test = require('/data/mytest.js');
donât use require when you want to get file, try use âfsâ package, it works for me
btw
if you create your own module you need to install it when you install n8n, it looks like this
n8nFolder â npm I âŚ/yourModule
and then you can do, const myModule require(âyourModuleâ); myModule.myFunction();