I'm using codeship to autodeploy my nextjs app from github. My deployment script is as follows
ssh user@SERVER_IP 'cd projectfolder/; git checkout master; git pull; npm run build; pm2 delete app; pm2 start npm --name "app" -- start;'
If I don't delete the process first the app will be duplicated with the next push.
This config works fine, but I'm kinda not sure about that deleting thing, since I found that there is a cleaner command like startOrRestart that will start a new one or restart existing process with the same name. I couldn't get it working though.