Monday, September 19, 2016

Make node auto-restart on Windows

Whether it's recovering from an unexpected crash, or doing a quick reboot to update the server code, this four-line batch file is what you're looking for.

:start
node app.js
echo %date% %time% >> rebootlog.txt
goto :start

The third line is important here. Don't neglect proper logging or you might not realize there was any crash at all. After all, the point of this is to reduce downtime, not lazy error handling.

Happy coding.