# Failing to add/start Node Red in PM2

**URL:** <https://discourse.nodered.org/t/failing-to-add-start-node-red-in-pm2/82891>\
**Category:** General\
**Created:** [15 November 2023 16:33 UTC](https://discourse.nodered.org/t/failing-to-add-start-node-red-in-pm2/82891 "2023-11-15T16:33:12Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mikee1234K](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikee1234k/32/70283_2.png) [@Mikee1234K](https://discourse.nodered.org/u/Mikee1234K)\
**Post date:** [15 November 2023 16:33 UTC](https://discourse.nodered.org/t/failing-to-add-start-node-red-in-pm2/82891/1 "2023-11-15T16:33:12Z")

</div>

I used to start NR with PM2, but had to reinstall everything after a SSD crash. I followed the tuorials, but its not working. I am running Win11, installed NR via npm. I had NR in PM2, but it didnt start. I deleted it to re add it. But its not starting or adding. The file paths are correct I believe.

```auto
C:\Windows\System32>pm2 start red.js --node-red

  error: unknown option `--node-red'

C:\Windows\System32>pm2 start red.js
[PM2][ERROR] Script not found: C:\Windows\System32\red.js

C:\Windows\System32>pm2 start C:\Users\lenov\AppData\Roaming\npm\node-modules\node-red\red.js --node-red

  error: unknown option `--node-red'

C:\Windows\System32>pm2 start C:\Users\lenov\AppData\Roaming\npm\node-modules\node-red\red.js
[PM2][ERROR] Script not found: C:\Users\lenov\AppData\Roaming\npm\node-modules\node-red\red.js

C:\Windows\System32>pm2 start 'C:\Users\lenov\AppData\Roaming\npm\node-red' -- -v
[PM2][ERROR] Script not found: C:\Windows\System32\'C:\Users\lenov\AppData\Roaming\npm\node-red'

C:\Windows\System32>pm2 start 'C:\Users\lenov\AppData\Roaming\npm\node-red.cmd' -- -v
[PM2][ERROR] Script not found: C:\Windows\System32\'C:\Users\lenov\AppData\Roaming\npm\node-red.cmd'

C:\Windows\System32>pm2 start 'C:\Users\lenov\AppData\Roaming\npm\node_modules\node-red\red.js' -- -v
[PM2][ERROR] Script not found: C:\Windows\System32\'C:\Users\lenov\AppData\Roaming\npm\node_modules\node-red\red.js

```

---

<div class="post-metadata">

**Author:** ![nlecaude](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nlecaude/32/25_2.png) [@nlecaude](https://discourse.nodered.org/u/nlecaude)\
**Post date:** [15 November 2023 16:43 UTC](https://discourse.nodered.org/t/failing-to-add-start-node-red-in-pm2/82891/2 "2023-11-15T16:43:26Z")

</div>

--node-red is no an option that exists. If you installed node-red globally you'll want `pm2 start node-red`.

---

<div class="post-metadata">

**Author:** ![Mikee1234K](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikee1234k/32/70283_2.png) [@Mikee1234K](https://discourse.nodered.org/u/Mikee1234K)\
**Post date:** [15 November 2023 16:54 UTC](https://discourse.nodered.org/t/failing-to-add-start-node-red-in-pm2/82891/3 "2023-11-15T16:54:14Z")

</div>

I tried that. It adds NR to PM2, but it wont start

```auto
C:\Windows\System32>pm2 start node-red
[PM2] Starting C:\USERS\LENOV\APPDATA\ROAMING\NPM\NODE-RED.CMD in fork_mode (1 instance)
[PM2] Done.
┌────┬─────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├────┼─────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0 │ node-red │ default │ N/A │ fork │ 22256 │ 0 │ 1 │ stopped │ 0% │ 0b │ admin │ disabled │
└────┴─────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘

C:\Windows\System32>

C:\Windows\System32>pm2 start 0
[PM2] Applying action restartProcessId on app [0](ids: ['0'])
[PM2] [node-red](0) ✓
[PM2] Process successfully started
┌────┬─────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├────┼─────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0 │ node-red │ default │ N/A │ fork │ 5096 │ 0 │ 16 │ stopped │ 0% │ 0b │ admin │ disabled │
└────┴─────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘

```

---

<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:** [15 November 2023 19:23 UTC](https://discourse.nodered.org/t/failing-to-add-start-node-red-in-pm2/82891/4 "2023-11-15T19:23:25Z")

</div>

We can't tell what is wrong if you don't share the log.

---

<div class="post-metadata">

**Author:** ![Mikee1234K](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikee1234k/32/70283_2.png) [@Mikee1234K](https://discourse.nodered.org/u/Mikee1234K)\
**Post date:** [16 November 2023 09:14 UTC](https://discourse.nodered.org/t/failing-to-add-start-node-red-in-pm2/82891/6 "2023-11-16T09:14:16Z")

</div>

I finally found the log

[node-red-error.log](https://discourse.nodered.org/uploads/short-url/uq3UHrY8waJE4YbxOYmqXeBnCMc.log) (92.1 KB)

[pm2.log](https://discourse.nodered.org/uploads/short-url/zjY4Ll8BnPtgFnefNWYO2oEXYWm.log) (35.3 KB)

---

<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:** [16 November 2023 16:53 UTC](https://discourse.nodered.org/t/failing-to-add-start-node-red-in-pm2/82891/7 "2023-11-16T16:53:52Z")

</div>

And the log gives you the answer as expected.

```auto
SyntaxError: Invalid or unexpected token
...
C:\USERS\LENOV\APPDATA\ROAMING\NPM\NODE-RED.CMD:1
@ECHO off
^

```

Which implies that you are trying to run a Windows Batch file (.cmd) with something other than the Windows command shell (probably node.js at a guess).

Which almost certainly means that your startup command for PM2/Node-RED is incorrect.

---

<div class="post-metadata">

**Author:** ![Mikee1234K](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikee1234k/32/70283_2.png) [@Mikee1234K](https://discourse.nodered.org/u/Mikee1234K)\
**Post date:** [16 November 2023 17:09 UTC](https://discourse.nodered.org/t/failing-to-add-start-node-red-in-pm2/82891/8 "2023-11-16T17:09:25Z")

</div>

Ok. So, (for a person who does not know pm2 and doesnt understand node.js either), how would I add NR to pm2, and how do I get it to start ? I know how to delete NR of pm2, I did that before. My pm2 is autostarting too, so its 'just' adding NR...

---

<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:** [16 November 2023 17:18 UTC](https://discourse.nodered.org/t/failing-to-add-start-node-red-in-pm2/82891/9 "2023-11-16T17:18:24Z")

</div>

I don't know how you have things configured so I can't really say, I can only say how I have things configured and I don't auto-start my windows instance as I use it for development and it doesn't always need to run. Also, I install node-red in a specific way that may not be the way you've done it.

The documentation for PM2 is pretty good I seem to remember.

I have a PM2 config `ecosystem.config.js` in the root folder of where I have node-red installed.

```auto
// PM2 Configuration for running Node-RED test/dev

module.exports = {
    apps : [{
        name: 'Node-RED',
        script: 'D:/src/nr/node_modules/node-red/red.js',

        // Options reference: https://pm2.keymetrics.io/docs/usage/application-declaration/
        args: '--userDir ./data',
        watch: [
            // a bunch of watched folders/files that restart node-red if changed
        ],
        ignore_watch: [
           // a bunch of ignored folders/files
        ],
        env: {
            NODE_ENV: 'development',
        },
        env_production: {
            NODE_ENV: 'production'
        },
        error_file: 'D:/src/nr/logout.log', // default: $HOME/.pm2/logs/XXXerr.log
        out_file: 'D:/src/nr/logout.log', // default: $HOME/.pm2/logs/XXXout.log
        pid_file: 'D:/src/nr/nrtest.pid', // default: $HOME/.pm2/pid/app-pm_id.pid
        combine_logs: true,
        merge_logs: true,
    }],
}

```

This is how it is run `pm2 start ecosystem.config.js && pm2 logs` though I use an npm package.json file with defined scripts that do it for me.

As you can tell, auto-running Node-RED on Windows isn't quite as simple as on Linux. You will at least need to do some reading up on PM2.

---

<div class="post-metadata">

**Author:** ![Mikee1234K](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikee1234k/32/70283_2.png) [@Mikee1234K](https://discourse.nodered.org/u/Mikee1234K)\
**Post date:** [16 November 2023 17:32 UTC](https://discourse.nodered.org/t/failing-to-add-start-node-red-in-pm2/82891/10 "2023-11-16T17:32:18Z")

</div>

Way way over my head lol. I did read on the pm2 website, and followed the instructions, the result was not working as seen in my post. I do not have/need the ecosystem config as luckily I only have/need 1 instance of Node Red. I had it running in the past, but unfortunately the SSD crashed, and no backup... (note to self - backup EVERYTHING next time...)  
Maybe you have an idea if I tell you my setup.  
I installed node.js, then node-red via npm, for global use. Node Red is installed in C:/Users/lenov/AppData/Roaming/npm/  
I can start it in a cmd window by typing 'node-red', or double clicking node-red.cmd in above 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:** [16 November 2023 17:57 UTC](https://discourse.nodered.org/t/failing-to-add-start-node-red-in-pm2/82891/11 "2023-11-16T17:57:51Z")

</div>

> [@TotallyInformation](#):
>
> `D:/src/nr/node_modules/node-red/red.js`

So in my setup, the node.js script that actually runs node-red is here `D:/src/nr/node_modules/node-red/red.js` so yours is probably at `C:/Users/lenov/AppData/Roaming/npm/node_modules/node-red/red.js` or something like that, find the script then you can run it manually with `node C:/Users/lenov/AppData/Roaming/npm/node_modules/node-red/red.js` or wherever it actually is.

Then I _think_ (because I've not used a manual setup of PM2 for years) that you can probably do something like `pm2 node C:/Users/lenov/AppData/Roaming/npm/node_modules/node-red/red.js`? Please do go read the docs for PM2 though, it is your machine not mine.

---

<div class="post-metadata">

**Author:** ![Mikee1234K](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikee1234k/32/70283_2.png) [@Mikee1234K](https://discourse.nodered.org/u/Mikee1234K)\
**Post date:** [16 November 2023 18:57 UTC](https://discourse.nodered.org/t/failing-to-add-start-node-red-in-pm2/82891/12 "2023-11-16T18:57:37Z")

</div>

Thanks will give it a try (and read) tomorrow

---

<div class="post-metadata">

**Author:** ![Mikee1234K](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikee1234k/32/70283_2.png) [@Mikee1234K](https://discourse.nodered.org/u/Mikee1234K)\
**Post date:** [17 November 2023 08:56 UTC](https://discourse.nodered.org/t/failing-to-add-start-node-red-in-pm2/82891/13 "2023-11-17T08:56:15Z")

</div>

I had to change it slightly to pm2 start C:/Users/lenov/AppData/Roaming/npm/node\_modules/node-red/red.js`  
that demonized (whatever that is lol) it and started it without errors. Now I have to figure out how to restart NR automatically in pm2 when it crashes. PM2 already autostarts with Windows, so I'm nearly there.  
Thanks for your help, much appreciated

---

<div class="post-metadata">

**Author:** ![softy2k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/softy2k/32/23707_2.png) [@softy2k](https://discourse.nodered.org/u/softy2k)\
**Post date:** [17 November 2023 10:31 UTC](https://discourse.nodered.org/t/failing-to-add-start-node-red-in-pm2/82891/14 "2023-11-17T10:31:42Z")

</div>

After command :

> pm2 start C:/Users/lenov/AppData/Roaming/npm/node\_modules/node-red/red.js`

don't forget to save your task :

> pm2 save --force

pm2 will restart automatically node-red, there is no need to do anything extra

---

<div class="post-metadata">

**Author:** ![Mikee1234K](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikee1234k/32/70283_2.png) [@Mikee1234K](https://discourse.nodered.org/u/Mikee1234K)\
**Post date:** [17 November 2023 10:32 UTC](https://discourse.nodered.org/t/failing-to-add-start-node-red-in-pm2/82891/15 "2023-11-17T10:32:56Z")

</div>

I did pm2 save, but not with --force. Should I do it again ?

---

<div class="post-metadata">

**Author:** ![softy2k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/softy2k/32/23707_2.png) [@softy2k](https://discourse.nodered.org/u/softy2k)\
**Post date:** [17 November 2023 11:18 UTC](https://discourse.nodered.org/t/failing-to-add-start-node-red-in-pm2/82891/16 "2023-11-17T11:18:34Z")

</div>

You can try, there will be no problem

---

<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:** [16 January 2024 11:18 UTC](https://discourse.nodered.org/t/failing-to-add-start-node-red-in-pm2/82891/17 "2024-01-16T11:18:56Z")

</div>

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