# Best practice for sharing static object between instances of a node type

**URL:** https://discourse.nodered.org/t/best-practice-for-sharing-static-object-between-instances-of-a-node-type/10880
**Category:** Developing Nodes
**Created:** [7 May 2019 10:46 UTC](https://discourse.nodered.org/t/best-practice-for-sharing-static-object-between-instances-of-a-node-type/10880 "2019-05-07T10:46:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [7 May 2019 10:46 UTC](https://discourse.nodered.org/t/best-practice-for-sharing-static-object-between-instances-of-a-node-type/10880/1 "2019-05-07T10:46:31Z")

</div>

Where would one store a 'common object' for re-use across all node instances?

e.g. Lets say I am developing a node called `image` and on my flow there are 10 instances. I would like each instance (server side) to be able to access some shared object `{fonts:[...]}` that are initialised only once.  
PS. I don't mean a config node (this shared object has no parameters or user options and need only be created once & re-used by every node instance (server side only))

Hope that makes sense.

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [7 May 2019 10:57 UTC](https://discourse.nodered.org/t/best-practice-for-sharing-static-object-between-instances-of-a-node-type/10880/2 "2019-05-07T10:57:10Z")

</div>

Hey @Steve-Mcl,  
Is [this](https://discourse.nodered.org/t/sharing-a-single-instance/10342/6) perhaps of any help to you?  
Bart

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [10 May 2019 12:40 UTC](https://discourse.nodered.org/t/best-practice-for-sharing-static-object-between-instances-of-a-node-type/10880/3 "2019-05-10T12:40:07Z")

</div>

A node's js is kind of in 3 sections.

You have the "global" part, the `module.exports` part and the `RED.nodes.registerType` section. I think of these as 3 layers. The global and the `module.exports` layers are common to all instances. So if you hold a variable there - as long as you don't update it from within the registerType function, it should - I believe - be common to all instances.

This is due to the way that Node.js's `require` function works. When you require a module, it is only ever loaded once even if it is later "required" again.

Hopefully someone will correct me if I have that wrong but that's how I think it works. I am not, after all, a professional Node developer.

If you look at the code in the v2 branch of uibuilder, you will see that I've moved a number of bits of processing out into this layer so that it is only processed once. Including the provision of the API's that I create.
