Node.js: how to warn when a server crashes

How can I get a warning when my server crashes for any reason? Does HopToad use or any other service?

thanks

EDIT:

I am using Heroku for node.js. This does not allow me to run anything. I need something to get my code inside out, without having to start any other process.

thanks

+7
source share
5 answers

You can try to handle the uncaughtException event in your node.js program and make your own "warn me" there. Or you can use a service like robots uptime to track if your application is listening on a specified port, for example.

+9
source

Pretty few options!

monit , forever and supervisord are the ones that, in my opinion, stick out from the crowd.

Since @ rob-cowie already answered about the supervisor, here you get a few pointers to "forever" and "monit".

Monit is a generic solution for managing services on your computer β€” notifying and restarting them if it crashes or uses too many resources.

I have yet to find a good reason for the user’s supervisor, not for monit, but on the superisord mailing list I have seen offers to use monit to monitor the supervisor!

+2
source

One approach is to periodically check that you can successfully access the page you serve, see http://wasitup.com/ .

Another approach would be to monitor the server process on your computer. One good way to do this is to run node.js using Supervisord . It can restart the broken process and send you an email. There are many examples around intarwebs, including a deployment example

+1
source

I just put together a class that listens for unhandled exceptions, and when it sees it:

  • prints a stack trace to the console.
  • writes its own log file to it
  • sends you a stack trace
  • reboots the server (or kills it, it is up to you)

This will require a little tweaking for your application, as I haven't made it general yet, but these are just a few lines, and this may be what you are looking for!

It starts from your application, you do not need to include any other files (except nodemailer.js, if you want to receive notifications by mail ..)

Check this!

+1
source

If you are still using node.js on a hero, it is also worth a look at Nodejitsu. It has great node support and works forever, with email notifications if your app crash loops and other things. Very comfortably.

In addition to handling uncaughtException , I would avoid this because of its instability, and also noted in recent node.js api docs that it is unreliable and unstable. See http://nodejs.org/api/process.html#process_event_uncaughtexception

Use something like forever !

0
source

All Articles