1

My question is simple : I have a program written in nodejs and want to run it in an infinite loop in the language bash, is this possible?

1
#!/bin/sh

while true
do
   node <myapp>
done

you can also use it as a one liner while true; do; node ; done;

0

You can run your app in the background like so

$ node app.js &

If you are looking to keep a running node process, though, I would look into the forever package.

$ sudo npm install forever -g
$ cd /path/to/your/project
$ forever start app.js
3
  • 1
    Yes, I know But for the project I'm doing i needed to run it with bash – D4IVT3 Nov 4 '15 at 16:44
  • @D4IVT3 - Updated answer. I really wouldn't use a while-true loop because it will lock up your computer infinitely creating node processes. – OneCricketeer Nov 4 '15 at 16:48
  • @D4IVT3 - Also, you have node installed and therefore npm, so there is no reason not to use forever to start and monitor your node process. – OneCricketeer Nov 4 '15 at 16:50

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.