Restart automatically #134

brunobg opened this Issue Dec 26, 2016 · 7 comments


None yet

6 participants

brunobg commented Dec 26, 2016

What would be the best way to restart an enclose compiled software automatically? Something like forever.

serkanp commented Dec 26, 2016

If you are using Linux, then write 2 scripts. First script will loop your application if exit. Second one will be service in /etc/init.d that will start your application on startup.(I can provide you example scripts)
Also I use process.exit(number) to detect why exit. For example I use process.exit(3) to understand that there is a software update. My looping script gets the exit code, before restarting app again, it unzips file and put the contents to main folder, then starts the app again. If process.exit(9) it means user wanted to close the app.. Etc etc use your exit logics on your own..

If you are using Windows, use nssm to make your executable app as Windows service.. So windows will take care of successful restarts on exits..

On macos it's different :) you have to write daemon script in a different way.
So depending on os, you will get os.platform and write your update process

To exit your app use process.exit()

Forever and other systems runs before your app.js, it detects exit and starts your app.. I could not find a better way to restart app on compiled app..

brunobg commented Dec 28, 2016

@serkanp thanks for the detailed answer. I was trying to avoid writing my own solution, since it should take care of infinite loops and so on and have something more easily portable but it's a solution nevertheless.

@czjs2 awesome suggestion, I didn't know pm2. Did you use pm2 with enclosejs? Any tips?

czjs2 commented Dec 29, 2016 edited

@brunobg i using pm2 with enclosejs on many project. pm2 is Production process manager for Node.JS applications with a built-in load balancer .


I have installed module PM2 and enclose module both in my application and after that I have run command
enclose index.js
it created a exe file. So would that file restart automatically when that will crash or stop?
Do I need to run another command here? Please Suggest!


Probably no. AFAIK PM2 is run outside your application and it controls only Node.js scripts. You should make your exe file run as a service/daemon.


EncloseJS executable works fine with pm2 on Debian. I use:
enclose server.js
that generates server and on production machine:
pm2 server
Here the docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment