Pm2 and n8n as a service

I’m currently having a problem with my n8n installation on a raspberry pi. For the last 8 months it’s run without any issues as a service via pm2. Just the other day I had an issue with the pi and after a few days was finally able to reboot it (not sure what the issue is).

Since then n8n no longer starts at boot. pm2 list shows nothing listed. I’ve reinstalled both pm2 and n8n.

Currently when I try to start n8n via pm2 I get the following error : “[PM2][ERROR] Script not found: /home/pi/n8n”

Any ideas? Thanks in advance for any help!

Hey @rgv,

Are you using an ecosystem file? You would need to run the start command in the directory that contains the file.

No I’m not using an ecoservice file. When I set it up months ago I just used the information in this tutorial

It looks pm2 is saying there is no script under /home/pi/n8n, When you installed n8n did you use the -g option?

A quick test might be to see if you can run n8n start.

Thanks for your help.

Yes I reinstalled n8n with -g and n8n start works correctly

Are you using the same user to run the pm2 command? What command are you actually running?

The same user yes. And for the command it’s

pm2 start n8n

I would have expected that to work but I don’t really know a great deal about pm2, What if you run which n8n to get the path then cd into that directory and run the pm2 command from there?

I remember that when I installing node or pm2, sudo had to be used. This caused pm2 to not be able to do anything with the commands. That’s why I switched to a node version manager (nvm) and that solved a lot of problems.

This doesn’t explain your problem and it’s not a 1:1 solution, but it might be a workaround.

Side note: If you install multiple Node versions, you have to make sure that all packages are installed in their respective folders. Managing pm2 over multiple node versions is not recommended. But you can use the ecosysfiles to specify which node version you want to use by specifying the path.

1 Like

Sorry for the delay, not very available over the weekend…

running “Which n8n” or “which pm2” returns nothing.

@BillAlex I understand what your suggesting, but I’m not sure how to check this…

start n8n works normally and when is run the n8n environment functions correctly…

I’m still quite lost here on what else to try…

Hey @rgv,

Normally if n8n is installed globally through NPM you would see a path back assuming npm is correctly installed. When I run the command on my little Linux powered Nuc I get the below response back.

[email protected]:~$ which n8n
/home/jon/.nvm/versions/node/v16.17.0/bin/n8n

When you installed node did you use nvm?