0

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.

0

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:

sudo su;

navigate to your project folder, and add your javascript file to pm2:

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:

pm2 monit;

or you can view the logs of all your nodejs apps:

pm2 logs;

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.

  • I tried doing it with pm2 but the pm2 monit command shows the same error: close code error 1. I can't figure out the problem as my program runs successfully when i start it manually but it shows the close code error when i add it to cron or pm2 on startup. I am not able to understand that what could be the problem? – Bansari Jun 3 '17 at 5:52
  • do you have any global dependencies that you installed as pi but NOT as root? This could be the issue. What does pm2 logs output? You must have some NodeJs Error output. – Audstanley Jun 4 '17 at 5:29
  • Nope, I don't have any global dependencies that are not installed as root. pm2 logs output shows 'close code is 1'. There is no other error as the node js script is running when i manually run the program in terminal. – Bansari Jun 5 '17 at 3:35
  • Do you have a link to your project on GitHub, or gist to the js code? Maybe I can recreate the problem on one of my raspberry pi's. If there are no external hardware dependencies then I can see what you're seeing. As a side note, which version of NodeJs are you running? I have a script that will get you to the latest. github.com/audstanley/NodeJs-Raspberry-Pi – Audstanley Jun 5 '17 at 13:11
  • ...check which version of NodeJs you are running as root, and which version you are running as pi. It is possible that you could be running two different version. github.com/audstanley/NodeJs-Raspberry-Pi – Audstanley Jun 5 '17 at 13:14

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.