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.
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.
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...
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.
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
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.
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