Is there any easy way that I can import my own functions and use them inside a function node?
So for example I have a function A that will take in a value do some logic and return a value B. I would like to be able to use this function A in multiple the function nodes across the project. So if needed, I could edit the logic of function A and then it returns a new value C and this new logic can be applied across all the function nodes.
Just wondering how this can be done easily and how the editing of the function A can be done easily as well.
The "traditional" way is to set your function up in a node.js module. This means simple "exporting" the function and doing a require of that module in Node-RED's settings.js file.
mymodule.js
module.exports = {
function myfn1(someParam) {
// .... my code ...
}
// ... more functions if you want to ...
}
In the globals section of settings.js
myStuff = require('./mymodule'), // this assumes you put the file in the same folder as settings.js