Alexander Rechsteiner Alexander Rechsteiner - 4 months ago 9x
Node.js Question

How to crash my Node app on purpose?

I've been working on a deployment work flow with Dokku and Docker and now I want to take care of continuity of my app (along the lines of Forever). To test it, I need a way to deliberately crash my app.

I created a new route '/crashme' with a function that is supposed to wreck my app.

Haven't found a way that worked locally with node/nodemon so far, I've tried:

  • Division by zero

  • Throw a new user exception

  • Referencing a variable that doesn't exist

None of those things crash the app to a point where it needs to be restarted.

Just how can I bring it down?


Three things come to my mind:

  • You could just call process.exit. This for sure brings your application to a state where it needs to be restarted.
  • The other option might be to run an endless loop, something such as while (true) {}. This should make Node.js use 100% of your CPU, and hence the application should be restarted as well (although this, of course, means that you / someone has to watch your application).
  • Create a module in C that crashes by e.g. trying to access a random place in memory. I have no such module at hand, but I'm pretty sure that it should be quite easy for someone with C skills to write such a module.