How to use other js files

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

ex>
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: https://nodered.org/docs/user-guide/writing-functions#loading-additional-modules

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

quickly:
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.

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

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

4 Likes

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.