# How to use other js files

**URL:** https://discourse.nodered.org/t/how-to-use-other-js-files/18999
**Category:** General
**Created:** [10 December 2019 15:42 UTC](https://discourse.nodered.org/t/how-to-use-other-js-files/18999 "2019-12-10T15:42:15Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![john88](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@john88](https://discourse.nodered.org/u/john88)
#### Post date: [10 December 2019 15:42 UTC](https://discourse.nodered.org/t/how-to-use-other-js-files/18999/1 "2019-12-10T15:42:15Z")

</div>

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; }

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/3c90ed4a7f3888610aea9c1ec88b769100ab194b.png)

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

thanks, Till

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [10 December 2019 17:34 UTC](https://discourse.nodered.org/t/how-to-use-other-js-files/18999/2 "2019-12-10T17:34:32Z")

</div>

The docs cover how to include additional modules in the Function node here: [https://nodered.org/docs/user-guide/writing-functions#loading-additional-modules](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.

---

<div class="post-metadata">

### Author: ![Nxito](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nxito/32/88293_2.png) [@Nxito](https://discourse.nodered.org/u/Nxito)
#### Post date: [11 December 2019 08:11 UTC](https://discourse.nodered.org/t/how-to-use-other-js-files/18999/3 "2019-12-11T08:11:27Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/9974633bc3f8a780d8d89bcab5feb811a90057cb.png)  
then in the fncion node you call this library with global.get  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/526447cfc0ae7070cb837642e7f68c88eddecd83.png)

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

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [11 December 2019 09:50 UTC](https://discourse.nodered.org/t/how-to-use-other-js-files/18999/4 "2019-12-11T09:50:03Z")

</div>

> [@Nxito](#):
>
> quickly:

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

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [11 December 2019 10:31 UTC](https://discourse.nodered.org/t/how-to-use-other-js-files/18999/5 "2019-12-11T10:31:49Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Nxito](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nxito/32/88293_2.png) [@Nxito](https://discourse.nodered.org/u/Nxito)
#### Post date: [11 December 2019 11:42 UTC](https://discourse.nodered.org/t/how-to-use-other-js-files/18999/6 "2019-12-11T11:42:41Z")

</div>

oh 😅 that happens to me to read everything in leaps

---

<div class="post-metadata">

### Author: ![john88](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@john88](https://discourse.nodered.org/u/john88)
#### Post date: [11 December 2019 13:23 UTC](https://discourse.nodered.org/t/how-to-use-other-js-files/18999/7 "2019-12-11T13:23:03Z")

</div>

Thank you . I will try.

---

<div class="post-metadata">

### Author: ![john88](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@john88](https://discourse.nodered.org/u/john88)
#### Post date: [11 December 2019 13:24 UTC](https://discourse.nodered.org/t/how-to-use-other-js-files/18999/8 "2019-12-11T13:24:24Z")

</div>

Thank you for reply. I will try.
