# Sharing a single instance

**URL:** https://discourse.nodered.org/t/sharing-a-single-instance/10342
**Category:** Developing Nodes
**Created:** [18 April 2019 20:06 UTC](https://discourse.nodered.org/t/sharing-a-single-instance/10342 "2019-04-18T20:06:48Z")
**Posts on this page:** 1
**Showing post:** 6

<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: [19 April 2019 21:30 UTC](https://discourse.nodered.org/t/sharing-a-single-instance/10342/6 "2019-04-19T21:30:34Z")

</div>

@cinhcet, @dceejay,  
Thanks but I thought using (node/flow/global) contexts wouldn't be a good solution in this case. Suppose I would do it like this:

```auto
var mitm = new Mitm();
this.context().global.set(mitm);

```

Inside that constructor the whole interception stuff is being setup. So what happens if a Node-RED contextstore is storing and loading that instance? Therefore I thought it would be better to avoid using the context???

> [@TotallyInformation](#):
>
> Anything that you put outside the function you include in `RED.nodes.registerType()` (param 2) is common to all instances of your node.

@TotallyInformation: Suppose I do it like this:

```auto
module.exports = function(RED) {
    var Mitm = require("mitm");
    
    var mitm = new Mitm();

    function HttpLoggerNode(config) {
        RED.nodes.createNode(this, config);

   }

    RED.nodes.registerType("http-logger",HttpLoggerNode);
}

```

Do you mean that the "mitm" variable is only initialized once (i.e. constructor is only executed once), and available to all the HttpLoggerNode's in my flow?

---

_[View the full topic](https://discourse.nodered.org/t/sharing-a-single-instance/10342)._
