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?


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).

  • Is using cron a firm requirement? If you just want to start a node server on boot using systemd offers a lot more flexibility in terms of restarting, which user is running the process, environment variables and so on?
    – tobyd
    Feb 2 '17 at 10:50
  • @tobyd not really a requirement. It seemed easier though. I'll switch if this isn't possible using cron but right now I'd like to know why this isn't working. Feb 2 '17 at 11:23
  • you could try adding an & to the end of your script definition to background it. I'm not entrely sure cron would be happy running a foreground task on boot? That would be my only suggestion. The echo hi bit would be fast and not cause problems but you might find the OS kills off the node process early on for causing a delay.
    – tobyd
    Feb 2 '17 at 11:38
  • made it work with this: weworkweplay.com/play/raspberry-pi-nodejs Feb 3 '17 at 10:08

Just like @tobyd said: it was better to not use cron. No idea why. I made it work using this tutorial: http://weworkweplay.com/play/raspberry-pi-nodejs/

  • For a marginally more flexible solution you could use either supervisor (supervisord.org/running.html) or systemd (freedesktop.org/software/systemd/man/systemd.service.html) to handle automatic restarts for you. rc.local IRC doesn't handle this scenario and node apps can be problematic on failure. Glad its sorted though.
    – tobyd
    Feb 3 '17 at 11:04
  • Please accept your own answer with a click on the tick on its left side. Only this will finish the question and it will not pop up again year for year.
    – Ingo
    Dec 11 '19 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.