# Node red doesn't restart after npm audit fix

**URL:** <https://discourse.nodered.org/t/node-red-doesnt-restart-after-npm-audit-fix/44652>\
**Category:** General\
**Created:** [24 April 2021 10:29 UTC](https://discourse.nodered.org/t/node-red-doesnt-restart-after-npm-audit-fix/44652 "2021-04-24T10:29:24Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![danipenn](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@danipenn](https://discourse.nodered.org/u/danipenn)\
**Post date:** [24 April 2021 10:29 UTC](https://discourse.nodered.org/t/node-red-doesnt-restart-after-npm-audit-fix/44652/1 "2021-04-24T10:29:24Z")

</div>

Hi to all,  
I've a big big problem, PLEASE HELP 😭 i'm desperate,  
it's about some month that I work on a project and.... I've not flow backup

the story is:  
I need to use moment inside a function node and after looking on node red forum I've found [https://discourse.nodered.org/t/using-moment-in-function-node/25651](https://discourse.nodered.org/t/using-moment-in-function-node/25651)

I decided to try and searched node-red setting.js to add moment:require('moment')  
the npm install moment (on the same dir)

after that npm says

```auto
found 6 vulnerabilities (2 low, 2 moderate, 2 high) in 338 scanned packages
  run `npm audit fix` to fix 4 of them.
  1 vulnerability requires semver-major dependency updates.
  1 vulnerability requires manual review. See the full report for details.

```

like and idiot i run `npm audit fix` on the same dir and I made the omelet 😭 😭 😭

now node-red doesn't start and if I try manually to start says:

```auto
Starting as a systemd service.
/usr/lib/node_modules/node-red/red.js:326
}).otherwise(function(err) {
   ^
TypeError: undefined is not a function
    at Object.<anonymous> (/usr/lib/node_modules/node-red/red.js:326:4)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47
nodered.service: Main process exited, code=exited, status=1/FAILURE
nodered.service: Failed with result 'exit-code'.
nodered.service: Service RestartSec=100ms expired, scheduling restart.
nodered.service: Scheduled restart job, restart counter is at 61.
Stopped Node-RED graphical event wiring tool.
Started Node-RED graphical event wiring tool.
/usr/lib/node_modules/node-red/red.js:326
}).otherwise(function(err) {
   ^
TypeError: undefined is not a function
    at Object.<anonymous> (/usr/lib/node_modules/node-red/red.js:326:4)
    at Module._compile (internal/modules/cjs/loader.js:1158:30).......

```

recursively.

I don't know what can I do to restore.  
Someone can help me please???

Thanks a lot.  
D.

---

<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:** [24 April 2021 10:49 UTC](https://discourse.nodered.org/t/node-red-doesnt-restart-after-npm-audit-fix/44652/2 "2021-04-24T10:49:16Z")

</div>

> [@danipenn](#):
>
> it's about some month that I work on a project and.... I've not flow backup

Well make a backup of the flows file immediately, the errors are nothing to do with your actual flow, but are due to installed node issues. Back up everything in the .node-red directory except node\_modules.

I suggest you start by removing the node\_modules folder and also remove package-lock.json (not package.json). Then go into your .node-red folder and run  
`npm install`  
That will reinstall all the nodes back to the version in package.json (it may take a while on a low power machine). If you still have problems then post package.json here and tell us what the problem is. Also tell us what hardware/OS you are running on and in a terminal run  
`node-red`  
and post the full output here.

---

<div class="post-metadata">

**Author:** ![danipenn](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@danipenn](https://discourse.nodered.org/u/danipenn)\
**Post date:** [24 April 2021 11:52 UTC](https://discourse.nodered.org/t/node-red-doesnt-restart-after-npm-audit-fix/44652/3 "2021-04-24T11:52:40Z")

</div>

I'm on RPi 3 with Raspbian OS v10.7  
node-red v1.0.4  
node v12.16.1  
npm v6.13.4

now i've seen that .node-red folder is under /home/pi.

changes I made are on /usr/lib/node\_modules/node-red and i execute (with sudo) npm command on this prompt.

```auto
I suggest you start by removing the node_modules folder and also remove package-lock.json (not package.json).

```

Ok, I made it

```auto
 Then go into your .node-red folder and run
npm install

```

in my .node-red folder under /home/pi.....  
or  
under /usr/lib/node\_modules/node-red ???

---

<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:** [24 April 2021 12:07 UTC](https://discourse.nodered.org/t/node-red-doesnt-restart-after-npm-audit-fix/44652/4 "2021-04-24T12:07:42Z")

</div>

> [@danipenn](#):
>
> changes I made are on /usr/lib/node\_modules/node-red and i execute (with sudo) npm command on this prompt.

You didn't make that clear, in that case it is node red itself you have messed up, so my suggestions will not help.  
Instead run the node red install/upgrade script from the node red docs for installing on the pi, that should reinstall node red and probably fix it.

---

<div class="post-metadata">

**Author:** ![danipenn](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@danipenn](https://discourse.nodered.org/u/danipenn)\
**Post date:** [24 April 2021 14:27 UTC](https://discourse.nodered.org/t/node-red-doesnt-restart-after-npm-audit-fix/44652/5 "2021-04-24T14:27:00Z")

</div>

OK @Colin  
I made it with

```auto
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)

```

after few minutes later all is done.

Node-red is restarted, now i'm going to re-install all missing modules of my project.

thanks

---

<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:** [24 April 2021 14:32 UTC](https://discourse.nodered.org/t/node-red-doesnt-restart-after-npm-audit-fix/44652/6 "2021-04-24T14:32:29Z")

</div>

> [@danipenn](#):
>
> now i'm going to re-install all missing modules of my project.

Running `npm install` in the .node-red folder (as previously suggested) should have done that for you.

---

<div class="post-metadata">

**Author:** ![danipenn](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@danipenn](https://discourse.nodered.org/u/danipenn)\
**Post date:** [24 April 2021 15:12 UTC](https://discourse.nodered.org/t/node-red-doesnt-restart-after-npm-audit-fix/44652/7 "2021-04-24T15:12:03Z")

</div>

I made it and (two times, one as pi user one as root) and it resolve many modules but not all, get some error because some modules is not updated and not compatible with new node-red (serialport i.e.)  
and this is result...

````auto

MySQLdatabase
ui_tab
ui_base
ncd-comm
ui_group
ui_spacer
ui_template
camerapi-takephoto
ui_gauge
ui_text
ui_text_input
ui_dropdown
mysql
moment
ui_date_picker
ui_button
join-wait
ncd-ads1115
base64
ui_led
ui_switch
ui_chart
ui_text-input
ui_ui_control
InvertUltimate
BooleanLogicUltimate```

now I try manually or you suggest me to try " npm install" on /usr/lib/node_module/node-red ?
````

---

<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:** [24 April 2021 15:19 UTC](https://discourse.nodered.org/t/node-red-doesnt-restart-after-npm-audit-fix/44652/8 "2021-04-24T15:19:59Z")

</div>

> [@danipenn](#):
>
> one as root

The only thing you should do as root is to install global modules (using `npm install -g`) which there is generally no need to do.

What did you do as root?

> [@danipenn](#):
>
> `now I try manually or you suggest me to try " npm install" on /usr/lib/node_module/node-red ?`

Absolutely not. In your .node-red folder (usually /home/pi/.node-red) which is where the flows file is. Where did you get the idea that you should do anything in /usr/lib? Don't.

---

<div class="post-metadata">

**Author:** ![danipenn](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@danipenn](https://discourse.nodered.org/u/danipenn)\
**Post date:** [24 April 2021 15:38 UTC](https://discourse.nodered.org/t/node-red-doesnt-restart-after-npm-audit-fix/44652/9 "2021-04-24T15:38:16Z")

</div>

I did it twice because the first time i did as user pi "npm install" then I got errors, I thought there were errors because I had to do as root.

I execute  
/home/pi/.node-red# sudo npm install

as I said in the first msg in the dir / usr / lib / ......  
I placed in the setting.js file "moment: require ('moment')  
execute npm install moment

and execute "npm audit fix"  
because npm said to run it to fix security issues

---

<div class="post-metadata">

**Author:** ![danipenn](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@danipenn](https://discourse.nodered.org/u/danipenn)\
**Post date:** [24 April 2021 16:22 UTC](https://discourse.nodered.org/t/node-red-doesnt-restart-after-npm-audit-fix/44652/10 "2021-04-24T16:22:56Z")

</div>

I re-install modules one by one from node-red palette,  
I erase modules that was unnecessary for my project  
and now i'm working.

many many thanks for your help. 🙏 🙏 🙏

---

<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:** [24 April 2021 16:39 UTC](https://discourse.nodered.org/t/node-red-doesnt-restart-after-npm-audit-fix/44652/11 "2021-04-24T16:39:21Z")

</div>

You are not the first to be messed up by running `npm audit`. Those messages are not something the node-red team has any control over.

Having used sudo with npm for local nodes you may find you have files under your home directory owned by root which may cause you problems installing or removing nodes in the future. If you do then you need to set all files in your home directory back to being owned by the node-red user (probably pi).

---

<div class="post-metadata">

**Author:** ![danipenn](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@danipenn](https://discourse.nodered.org/u/danipenn)\
**Post date:** [24 April 2021 16:52 UTC](https://discourse.nodered.org/t/node-red-doesnt-restart-after-npm-audit-fix/44652/12 "2021-04-24T16:52:21Z")

</div>

> [@Colin](#):
>
> Having used sudo with npm for local nodes you may find you have files under your home directory owned by root which may cause you problems installing or removing nodes in the future. If you do then you need to set all files in your home directory back to being owned by the node-red user (probably pi).

yes, some modules had root:root as owner:group, I change this like the others pi:pi but....  
dashboard doesn't work, when I open localhost:1880/ui it open screen with this like the first time

Welcome to the Node-RED Dashboard  
Please add some UI nodes to your flow and redeploy.

---

<div class="post-metadata">

**Author:** ![danipenn](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@danipenn](https://discourse.nodered.org/u/danipenn)\
**Post date:** [24 April 2021 17:02 UTC](https://discourse.nodered.org/t/node-red-doesnt-restart-after-npm-audit-fix/44652/13 "2021-04-24T17:02:43Z")

</div>

I think when (out of ignorance) I ran "npm audit fix" under "/usr/lib/node\_module/node-red" I shit and now, I can see the flow, I have all nodes configured as before, tab and group of the dashboards are in place but the dashboard does not start.

inside the dir "/usr/lib/node\_module" the dir "node-red" has disappeared

moreover, before to enter node-red and the dashboard I used the username and password that I had set in the node-red configuration, now there is no longer the request.

😭

---

<div class="post-metadata">

**Author:** ![danipenn](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@danipenn](https://discourse.nodered.org/u/danipenn)\
**Post date:** [24 April 2021 17:29 UTC](https://discourse.nodered.org/t/node-red-doesnt-restart-after-npm-audit-fix/44652/14 "2021-04-24T17:29:02Z")

</div>

SOLVED.

problem of dashboard was that I had ncd-comm module not installed but a configuration in a flow that used it and deploy stop before to start.  
I deleted this and now I'm really working.

---

<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:** [24 April 2021 19:17 UTC](https://discourse.nodered.org/t/node-red-doesnt-restart-after-npm-audit-fix/44652/15 "2021-04-24T19:17:45Z")

</div>

TWo learning points here:

1. NEVER run `npm audit fix` unless you REALLY know what you are doing. It will nearly always break something.

2. If you get totally in a mess with installed modules, don't forget that you can always delete the `node_modules` folder as long as you have a matching package.json file that contains the module details. Then you can simply do an `npm install` and everything will be restored.

A bonus 3rd learning point is that it is highly recommended that you learn the basics of npm and the file/folder structures it produces. It doesn't take much and it will really help you out in the future.

---

<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:** [8 May 2021 19:18 UTC](https://discourse.nodered.org/t/node-red-doesnt-restart-after-npm-audit-fix/44652/16 "2021-05-08T19:18:13Z")

</div>

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