Running node script on startup with cron

I know this has been as been asked before. I followed lots of tuts how to do this and I want to do it with cron.

First problem is sudo vs regular user. I write in nodeJS, while I managed to have both users on the same up-to-date node version I’d prefer not to use sudo.

This is what I tried:

  1. which node outputs /home/pi/.nvm/versions/node/v7.5.0/bin/node
  2. crontab -e and use nano
  3. I add @reboot /home/pi/.nvm/versions/node/v7.5.0/bin/node /home/pi/projects/pi-bootup/server.js, exit and save.
  4. I insert /home/pi/.nvm/versions/node/v7.5.0/bin/node /home/pi/projects/pi-bootup/server.js to test if the command works (it does).
  5. I check with ps -e|grep node for running node tasks (yup, they’re there)
  6. sudo reboot.
  7. after reboot, I check for running node tasks with ps -e|grep node. None started.

What am I doing wrong?

EDIT:

I also added @reboot echo "hi" > /home/pi/reboot.txt 2>&1 and the file is created after reboot. So the reboot jobs run, just the node task isn’t running… or am I verifying this the wrong way?

Thanks in advance for any help. I’m new to Raspberry and Linux, (kinda new to node too).

Leave a Reply

Your email address will not be published. Required fields are marked *