How to use other js files

I want to use other js file in a function node.
How can I use it?

my.js file

function AAA () {
var result = "hi";
return result;

How can I use the AAA functions in my.js file inside a function node?

thanks, Till

The docs cover how to include additional modules in the Function node here:

The key thing is it has to be packaged as a node.js module and then added to the global context object.

you add in the section functionGlobalContext ( in your settings.js file located in the folder where you installed node-red) the library as in the image.

then in the fncion node you call this library with global.get

This and much more is found in the documentation, it is good to take a look

1 Like

I think they want to include functions from their own .js file, not an existing node.js package, so they need to do what @knolleary says and make their file into a package first.

Which probably isn't worth it for just simple functions

but is a good skill to have if you want to learn/use nodejs


oh :sweat_smile: that happens to me to read everything in leaps

1 Like

Thank you . I will try.

Thank you for reply. I will try.