Search code examples
node.jsreactjsnext.jsserverpm2

pm2 not running next.js


I have next.js application on an apache server.I was running npm run start in my terminal and it is working as expected, starting build website. problem is that when I close terminal, service stops. I know that I have to use pm2 for that and I have installed it globally, problem is that it is not running. am trying this command

pm2 start npm --name "khulo" -- start

my application name is "khulo". this is the output I get from terminal:

enter image description here

therefore as far as I understand, there is no process and therefore there is no service on my server. what is the problem? am running that command in my root project

edit: I know that I need priviliges as an user to start pm2, but am not root user, therefore now am asking what privillege do I need as a non-root user to control pm2?


Solution

  • I have a nextjs app running with the same command that is connected to the nodejs backend. I start with the sudo permissions by running sudo su

    pm2 start npm --name "khulo" --start
    

    To start with the non-root user, try the following link

    https://stackoverflow.com/a/65461743