I have a headless Raspberry Pi running a simple NodeJS application.
The only interface I have attached to the Pi is a single push-button which starts and stops a timelapse video recording.
I know it's not good practice to cut the power to the Pi without a proper shutdown, so I want to add a shutdown command to Node.
Using ShellJS, I can do this very simply - if the user holds down the push-button for five seconds, I can call
shell.exec('sudo shutdown -h now');
which will shutdown the Pi. This works as expected when I'm connected to the Pi via ssh and I call the node command myself ('node app.js'). But my goal is to have my Node app running automatically on startup. I'm doing that by using '/etc/rc.local' to call the script on boot:
su pi -c 'node /path/to/app.js'
In this case the shutdown command does not work, and I don't even know how to access the node console to see what kind of error it's throwing. Can someone point me in the right direction here?