PM2 is a fantastic tool to manage scripts on a raspberryPI

It will keep them running even if the PI reboots, but I needed to start / stop my script on a specific schedule, to do this I used cron

0 16 * * * /usr/local/bin/node /usr/local/bin/pm2 start timelapse
0 8 * * * /usr/local/bin/node /usr/local/bin/pm2 stop timelapse

‘timelapse’ is the internal PM2 name for my script. To find out the location of pm2 and node, run

which node
which pm2