Load Function Code from File

Hi. starting off on node red - awesome tool!
Question: Have functions in a flow for which i maintain the code in files and save in e.g. node-red\lib\functions\actions.js
External because using other editor (vscode/notepadd++)

Inconvenience is, every time i change the function externally in the editor and save, i'll have to double-click the function node, hit the arrow down button next to name, and select the file actions.js., ctrl+enter, control+d, --> lots of clicks

Anyway to automate that? So that when the flow starts it refreshes the function with the actions.js file?

btw - using node-red with as the home assistant plugin.

Cheers!

If you change your settings so that the monaco editor is used, then the function node editor becomes a lot more like VSCode. Then you can do what most others to & simply edit the function code in the node-red editor?

Not quite like you describe but you have a couple of ways to include functions from files using standard node.js features. Either by requireing the file in the globals section of the settings.js or by creating a module that works with the modules section of the function node setup.

The down sides of those are that node-red has to be restarted to reload a new version of the file. However, that can be automated as well in a variety of ways.

Thanks Steve. i'm spoilt with monitor real estate so have the long function code open on a 32inch monitor in portrait while the flow is open in NR on a 32inch horizontal. The editor in NR cant be detached from the flow so that'll take away the advantages of using several screens.

But will definitely try the monaco for smaller flows/projects. great tip!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.