# Customize default/core nodes in user directory upon recreation/restart

**URL:** <https://discourse.nodered.org/t/customize-default-core-nodes-in-user-directory-upon-recreation-restart/60322>\
**Category:** General\
**Created:** [25 March 2022 02:43 UTC](https://discourse.nodered.org/t/customize-default-core-nodes-in-user-directory-upon-recreation-restart/60322 "2022-03-25T02:43:02Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![SnibbitySnab](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@SnibbitySnab](https://discourse.nodered.org/u/SnibbitySnab)\
**Post date:** [25 March 2022 02:43 UTC](https://discourse.nodered.org/t/customize-default-core-nodes-in-user-directory-upon-recreation-restart/60322/1 "2022-03-25T02:43:02Z")

</div>

Essentially, I regularly delete my user directory so that it may be automatically recreated upon restart of Node-RED, and I have to manually reinstall some contrib nodes that I regularly use. Which script do I need to modify in order to include these non-core nodes when the user directory is recreated?

---

<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:** [25 March 2022 07:54 UTC](https://discourse.nodered.org/t/customize-default-core-nodes-in-user-directory-upon-recreation-restart/60322/2 "2022-03-25T07:54:21Z")

</div>

Keep package.lock, package-lock.json and the node\_modules folder. That will keep all installed nodes.

---

<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:** [25 March 2022 09:15 UTC](https://discourse.nodered.org/t/customize-default-core-nodes-in-user-directory-upon-recreation-restart/60322/3 "2022-03-25T09:15:37Z")

</div>

And in the userDir, run:

```auto
npm install

```

After recreating the userDir if you have deleted the `node_modules` folder.

---

<div class="post-metadata">

**Author:** ![SnibbitySnab](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@SnibbitySnab](https://discourse.nodered.org/u/SnibbitySnab)\
**Post date:** [25 March 2022 14:08 UTC](https://discourse.nodered.org/t/customize-default-core-nodes-in-user-directory-upon-recreation-restart/60322/4 "2022-03-25T14:08:52Z")

</div>

Thanks. To be more specific, I'm looking for something more automated like how the default user folder is created automatically on restart if it is missing, but with additional nodes. I'm trying to avoid any manual steps, but instead modifying the default script behavior, if that's possible.

For instance, delete the existing user directory, start Node-RED, new user directory is automatically created like normal BUT with additional nodes that I commonly use.

---

<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:** [25 March 2022 15:05 UTC](https://discourse.nodered.org/t/customize-default-core-nodes-in-user-directory-upon-recreation-restart/60322/5 "2022-03-25T15:05:52Z")

</div>

That's an interesting idea. To have perhaps a post creation script ability. An optional script that runs after the userDir is created with the default files and folders.

That would let you do things like copy additional files and folders, make changes to the package.json (which is where your installed nodes are recorded), and let you run `npm install`.

Sounds like that might be an interesting feature request? Unless this gets shot down straight away, you might want to change the category for this thread from general to feature requests.

---

<div class="post-metadata">

**Author:** ![SnibbitySnab](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@SnibbitySnab](https://discourse.nodered.org/u/SnibbitySnab)\
**Post date:** [25 March 2022 17:05 UTC](https://discourse.nodered.org/t/customize-default-core-nodes-in-user-directory-upon-recreation-restart/60322/6 "2022-03-25T17:05:06Z")

</div>

I may make a separate post as a feature request, but I feel this can probably done by editing the existing scripting, but have not had enough experience diving into that to have a definitive answer.

---

<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:** [25 March 2022 18:54 UTC](https://discourse.nodered.org/t/customize-default-core-nodes-in-user-directory-upon-recreation-restart/60322/7 "2022-03-25T18:54:15Z")

</div>

> [@SnibbitySnab](#):
>
> this can probably done by editing the existing scripting

Which existing script do you mean?

---

<div class="post-metadata">

**Author:** ![SnibbitySnab](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@SnibbitySnab](https://discourse.nodered.org/u/SnibbitySnab)\
**Post date:** [25 March 2022 19:25 UTC](https://discourse.nodered.org/t/customize-default-core-nodes-in-user-directory-upon-recreation-restart/60322/8 "2022-03-25T19:25:37Z")

</div>

Stock .js scripts in the node-red package, like red.js. The user directory is created using local nodes when node-red is started and the user directory doesn't exist. You can already define a custom settings.js to be created in the user directory by modifying the one in node\_modules\node-red, so in the stock js scripts there likely is a way to modify how the default user directory is built.

For instance, if I have a certain configuration that I always want settings.js to be in my user directory, to persist after deletion of the user directory, you can modify the one in node\_modules\node-red and that will be the settings.js file used in the new user directory.

---

<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:** [25 March 2022 21:48 UTC](https://discourse.nodered.org/t/customize-default-core-nodes-in-user-directory-upon-recreation-restart/60322/9 "2022-03-25T21:48:32Z")

</div>

You are talking about modifying core node-red code. That works for you as a one-off but it forces you into a situation where you have to make more changes every time there is a new release of Node-RED and it forces you to distribute a custom version each time. That doesn't sound very sensible or sustainable even for just your current situation.

Then there is the possibility that this might benefit others - this is the core of open source.

Hence the reason I suggested that you should move this thread to the feature requests category so that Nick and others involved with core development will see it and be able to think about whether it is useful, whether there is an alternative and whether they would be happy with a PR.

---

<div class="post-metadata">

**Author:** ![SnibbitySnab](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@SnibbitySnab](https://discourse.nodered.org/u/SnibbitySnab)\
**Post date:** [26 March 2022 05:09 UTC](https://discourse.nodered.org/t/customize-default-core-nodes-in-user-directory-upon-recreation-restart/60322/10 "2022-03-26T05:09:51Z")

</div>

Well an update, as this is technically feasible without modifying core code. You can modify the 'nodesDir' property of settings.js located in the core node-red directory and have your js/html files for the nodes you want to persist in the directory of that property. Any dependencies for those nodes need to exist in the core node-red node\_modules directory as well.

When the user directory is created, node-red uses that settings.js file as the template for the settings.js file located in the user directory. So essentially you can have a directory containing user nodes that will persist through user directory deletes.

I'm sure this is a bastardization of the original intention of this property, but it does work, and should continue to work through node-red updates assuming that the 'nodesDir' property isn't deprecated/removed.

---

<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:** [26 March 2022 07:07 UTC](https://discourse.nodered.org/t/customize-default-core-nodes-in-user-directory-upon-recreation-restart/60322/11 "2022-03-26T07:07:01Z")

</div>

Have you tried installing another contrib node after the process you describe? After that do the additional modules you put in node\_modules remain there?

---

<div class="post-metadata">

**Author:** ![SnibbitySnab](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@SnibbitySnab](https://discourse.nodered.org/u/SnibbitySnab)\
**Post date:** [26 March 2022 08:57 UTC](https://discourse.nodered.org/t/customize-default-core-nodes-in-user-directory-upon-recreation-restart/60322/12 "2022-03-26T08:57:51Z")

</div>

Just tried and it seems to be working still.

Installed a new contrib package from palette manager and my my 'nodesDir' nodes are still there.  
Stopped/started node-red and they're still in the palette.  
Deleted the user directory and they still persist in the palette.

When adding them this way, node-red shows them under the 'node-red' package in the palette manager, and they do persist through deletion of the user directory and installation of other packages via the palette manager.

---

<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:** [26 March 2022 11:26 UTC](https://discourse.nodered.org/t/customize-default-core-nodes-in-user-directory-upon-recreation-restart/60322/13 "2022-03-26T11:26:40Z")

</div>

It was the additional dependencies that you said you were putting in node\_modules that I was concerned about. I suspect that npm will remove them because they do not appear in package.json

---

<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:** [26 March 2022 14:22 UTC](https://discourse.nodered.org/t/customize-default-core-nodes-in-user-directory-upon-recreation-restart/60322/14 "2022-03-26T14:22:10Z")

</div>

But this doesn't get away from the update problem. When you install a new version of Node-RED, your amended settings.js will be overwritten and you will have to replace it.

---

<div class="post-metadata">

**Author:** ![SnibbitySnab](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@SnibbitySnab](https://discourse.nodered.org/u/SnibbitySnab)\
**Post date:** [27 March 2022 01:36 UTC](https://discourse.nodered.org/t/customize-default-core-nodes-in-user-directory-upon-recreation-restart/60322/15 "2022-03-27T01:36:25Z")

</div>

Yes that's correct, but holds true for any modifications to settings.js i.e. credentials. Good practice i.e. taking a backup before upgrade in case issues are encountered should prevent any major problems.

---

<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:** [26 May 2022 01:37 UTC](https://discourse.nodered.org/t/customize-default-core-nodes-in-user-directory-upon-recreation-restart/60322/16 "2022-05-26T01:37:17Z")

</div>

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