# Same Node\_modules directory for multiple instances of node-red in a PC

**URL:** https://discourse.nodered.org/t/same-node-modules-directory-for-multiple-instances-of-node-red-in-a-pc/82784
**Category:** General
**Created:** [11 November 2023 13:10 UTC](https://discourse.nodered.org/t/same-node-modules-directory-for-multiple-instances-of-node-red-in-a-pc/82784 "2023-11-11T13:10:16Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)
#### Post date: [11 November 2023 13:10 UTC](https://discourse.nodered.org/t/same-node-modules-directory-for-multiple-instances-of-node-red-in-a-pc/82784/1 "2023-11-11T13:10:16Z")

</div>

How can I use same node\_modules directory to use the contrib nodes in separate instances of node-red.  
I have 3 instances of node-red running in a PC as windows service, by using NSSM.

> <https://gist.github.com/dceejay/576b4847f0a17dc066db>

the only issue i am facing is that i have to download the required contrib-nodes through pallet manager through each instance of node-red. how do i setup so that i dont need to download them separately into respective folders ?

below is the command line used for setting up 2 different folders/instances.  
where am i doing it wrong ?

```auto
nssm install NR-DB "c:\Users\\"%USERNAME%"\AppData\Roaming\npm\node-red.cmd"
nssm set NR-DB AppDirectory "c:\Users\\"%USERNAME%"\NR-DB"
nssm set NR-DB AppParameters "-u c:\Users\\"%USERNAME%"\NR-DB > c:\temp\nr-DB.log"
nssm set NR-DB Description "DB Logging"

```

```auto
nssm install NR-LIVE "c:\Users\\"%USERNAME%"\AppData\Roaming\npm\node-red.cmd"
nssm set NR-LIVE AppDirectory "c:\Users\\"%USERNAME%"\NR-LIVE"
nssm set NR-LIVE AppParameters "-u c:\Users\\"%USERNAME%"\NR-LIVE > c:\temp\nr-LIVE.log"
nssm set NR-LIVE Description "LIVE Status"

```

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [11 November 2023 13:38 UTC](https://discourse.nodered.org/t/same-node-modules-directory-for-multiple-instances-of-node-red-in-a-pc/82784/2 "2023-11-11T13:38:36Z")

</div>

If you install them globally (using `npm -g install ...`) then they will be available to any instance.

---

<div class="post-metadata">

### Author: ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)
#### Post date: [11 November 2023 14:30 UTC](https://discourse.nodered.org/t/same-node-modules-directory-for-multiple-instances-of-node-red-in-a-pc/82784/3 "2023-11-11T14:30:13Z")

</div>

Got it working. Thanks.  
Follow up question: Are there any pros or cons of having a global install (of both node-red and contrib nodes?)

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [11 November 2023 15:01 UTC](https://discourse.nodered.org/t/same-node-modules-directory-for-multiple-instances-of-node-red-in-a-pc/82784/4 "2023-11-11T15:01:51Z")

</div>

> [@smanjunath211](#):
>
> Are there any pros or cons of having a global install

Pro: everything has access to it.  
Con: everything has access to it.

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [11 November 2023 20:13 UTC](https://discourse.nodered.org/t/same-node-modules-directory-for-multiple-instances-of-node-red-in-a-pc/82784/5 "2023-11-11T20:13:13Z")

</div>

possible con: changing it in one flow `may` cause other flows to have an issue until you redeploy them

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [11 November 2023 20:49 UTC](https://discourse.nodered.org/t/same-node-modules-directory-for-multiple-instances-of-node-red-in-a-pc/82784/6 "2023-11-11T20:49:24Z")

</div>

> [@zenofmud](#):
>
> changing it in one flow

Do you mean upgrading a node? That should not be an issue I think. The upgraded node will not be used until node-red is restarted.

---

<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: [11 November 2023 23:58 UTC](https://discourse.nodered.org/t/same-node-modules-directory-for-multiple-instances-of-node-red-in-a-pc/82784/7 "2023-11-11T23:58:39Z")

</div>

> [@smanjunath211](#):
>
> Follow up question: Are there any pros or cons of having a global install (of both node-red and contrib nodes?)

Globally installed nodes may have more access to the system than is wise. This can open unexpected security issues.

Also, they can be hard to track down if you ever need to, the global folders are in weird (I think) positions that are quite different on different OS's.

As nodes are generally written to be locally installed to the userDir folder, they are probably not well tested as global installs. This can occasionally result in weird, hard to track down bugs.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [12 November 2023 09:55 UTC](https://discourse.nodered.org/t/same-node-modules-directory-for-multiple-instances-of-node-red-in-a-pc/82784/8 "2023-11-12T09:55:00Z")

</div>

> [@TotallyInformation](#):
>
> Globally installed nodes may have more access to the system than is wise.

How does that work? I would have thought that once node-red loaded the node into memory it wouldn't make any difference where it was loaded from.

> [@TotallyInformation](#):
>
> they can be hard to track down

Not exactly hard, though you do need to know how to find them.  
`npm list -g <node-name>`  
should tell you where the node\_modules folder that contains it is.

> [@TotallyInformation](#):
>
> they are probably not well tested as global installs. This can occasionally result in weird, hard to track down bugs.

Can you give an example of where it might make a difference at run time? I am not saying you are wrong, just that I can't immediately see how it might make a difference. Possibly something to do with paths I suppose.

---

<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: [12 November 2023 12:49 UTC](https://discourse.nodered.org/t/same-node-modules-directory-for-multiple-instances-of-node-red-in-a-pc/82784/9 "2023-11-12T12:49:56Z")

</div>

> [@Colin](#):
>
> > [@TotallyInformation](#):
> >
> > Globally installed nodes may have more access to the system than is wise.
> 
> How does that work? I would have thought that once node-red loaded the node into memory it wouldn't make any difference where it was loaded from.

Because the modules are installed to a root accessible area, any inherent low-level weakness (probably in node.js) could allow access to areas of the OS that they should not have.

> [@Colin](#):
>
> > [@TotallyInformation](#):
> >
> > they can be hard to track down
> 
> Not exactly hard, though you do need to know how to find them.  
> `npm list -g <node-name>`  
> should tell you where the node\_modules folder that contains it is.

Which is fine if you are an expert, but a PITA if you are a novice as many Node-RED users are. That is, after all, one of the main benefits of Node-RED.

> [@Colin](#):
>
> > [@TotallyInformation](#):
> >
> > they are probably not well tested as global installs. This can occasionally result in weird, hard to track down bugs.
> 
> Can you give an example of where it might make a difference at run time? I am not saying you are wrong, just that I can't immediately see how it might make a difference. Possibly something to do with paths I suppose.

I don't know that I have a direct answer. However, take the recent discussion about node-red-context-monitor that requires knowledge of where another module is. While we did eventually find a robust way of doing this, if assumptions are made about relative locations of files, this might not hold true when installed globally. In that case, it was the opposite issue, it was assumed that Node-RED was installed globally but that isn't the only case.

In my own code, I have several places where a node needs to be able to manipulate the filing system and in some cases it took many iterations to get it right, often edge cases being discovered by others.

Enough examples anyway to make me nervous about how stable some nodes might be even if it should be a rare issue. A lot of time then has to be spent tracking down the problem because the author rightly assumes that the package will be installed in a particular way.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [14 November 2023 09:34 UTC](https://discourse.nodered.org/t/same-node-modules-directory-for-multiple-instances-of-node-red-in-a-pc/82784/10 "2023-11-14T09:34:32Z")

</div>

All good points as usual.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [28 November 2023 09:35 UTC](https://discourse.nodered.org/t/same-node-modules-directory-for-multiple-instances-of-node-red-in-a-pc/82784/11 "2023-11-28T09:35:22Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
