I was looking to test a node server in a shared hosting environment.
I'm using an ssh terminal session to test.
The server works fine, but of course you can't leave the terminal session without stopping the server.
Using pm2 (npm package), I'm able to keep the server running, but on exiting the terminal session, the pm2 job quits as well, which stops the server. Curious why that would be.
Tried using a crontab to run a shell script that in turn runs the pm2 which in turn starts the node server. The cron tab runs every minute, but the node server never starts.
The sh script works just fine, pm2 works fine, and the node server works fine. What doesn't work: keeping the node server running after exiting the terminal session.
Here's the shell script that runs the pm2 to trigger the node server...
ps cax | grep node > /dev/null
if [ $? -eq 0 ]; then
echo "Process running."
else
echo "Process not running."
PATH=$PATH:/usr/local/bin
pm2 start '/path/to/NodeServer.js' --restart-delay=100
fi