I am using raspberry pi 3. I am using npm module pocketsphinx_continuous and it runs perfectly when I run node js code in the terminal. However, it shows 'close code error 1' when I try to run the same code using the command @reboot node myprogram.js in the crontab. If anyone has ran pocketshpinx on reboot, please provide your inputs to this issue.
I highly suggest you install pm2
You can very easily manage your node start-up applications. I install pm2 as root:
sudo npm install pm2 -g;
then switch to root user:
pm2 add myprogram.js --name myProgram
Then, what is great about pm2, is that it will handle the start up script for you:
pm2 save; pm2 startup;
...and you can monitor your app:
or you can view the logs of all your nodejs apps:
of course, you are running pm2 as sudo, so make sure your code is safe, but this alleviates not knowing why cron isn't running your script on startup. It could be a number of reasons. Environment variables is the most likely reason. Either way, pm2 saves you from writing shell scripts.
...and one more plug for pm2, I love that i can run multiple NodeJs versions with nvm in pm2. I have a webserver running on startup in Node version 4.x, and all my latest Node projects in version 8 simultaneously with nvm, and pm2. Amazing. And since you are running pm2 as root, you can verify why your app isn't working properly by checking the pm2 logs.