# Accessing external libraries

**URL:** <https://discourse.nodered.org/t/accessing-external-libraries/77340>\
**Category:** General\
**Created:** [7 April 2023 13:24 UTC](https://discourse.nodered.org/t/accessing-external-libraries/77340 "2023-04-07T13:24:31Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![msillano](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/msillano/32/17424_2.png) [@msillano](https://discourse.nodered.org/u/msillano)\
**Post date:** [7 April 2023 15:27 UTC](https://discourse.nodered.org/t/accessing-external-libraries/77340/2 "2023-04-07T15:27:55Z")

</div>

Developing a project involving many flows, I needed to create function libraries, function arrays, and singleton objects (with data and methods), shared and accessible from each node/flow.

The 'standard' solution (import etc.) doesn't excite me.  
I found a solution that works best for me: it uses singleton objects, and this is a good replacement for shared libraries, having the following advantages, also keeping the distribution issues in mind:

- Easy to implement.
- Easy to debug.
- Visible in node-red 'Context data' debug pad.
- No extra files: all in JSON import/export.
- No config file editing, auto-installation.

An implementation can be seen here: [‘Meteo Utils’ functions library](https://discourse.nodered.org/t/meteo-utils-functions-library-meteoutils-constructor/62977).

In short, place in 'On Start' of some function node, in your flow or in one flow of your project:

```auto
global.set("a_sing_obj", {}); // only data, empty in this example
context.global.a_sing_obj = global.get("a_sing_obj");

```

Then add methods, like:

```auto
context.global.a_sing_obj.one_method= function(....){
                // more code, you can use 'this.' here
                 }

```

done: then you can do calls like:

```auto
context.global.a_sing_obj.one_method(...)

```

in any node and in any flow or subflow.

---

_[View the full topic](https://discourse.nodered.org/t/accessing-external-libraries/77340)._
