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:
None of those things crash the app to a point where it needs to be restarted.
Just how can I bring it down?
When you find the node.exe file is causing problems or taking too many resources, you can consider ending the process. You just need to open Task Manager, right-click node.exe, and select End task.
Node normally exits with code 0 when no more async operations are pending. process. exit(1) should be used to exit with a failure code.
Three things come to my mind:
process.exit
. This for sure brings your application to a state where it needs to be restarted.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).I was attempting a similar thing with a /crash route in express, but just throwing an error from within the route handler was not enough to crash it.
process.exit would stop my app but forever would not restart it. (The forever logs just said something like process self terminated.)
What did work for me was inserting this into my /crash
route:
setTimeout(function () { throw new Error('We crashed!!!!!'); }, 10);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With