How to collapse a nodejs app appattically (for test)

I want to test crashing nodejs application, need to stop process, not just throw some errors. is there an easy way to do this programmatically?

app.get('/crash', function() {
  //do something to crash it 
})

      

thank!

+3


source to share


2 answers


Try the following:



app.get('/crash', function() {
  process.nextTick(function () {
    throw new Error;
  });
})

      

+9


source


process.exit(1)

      

http://nodejs.org/api/process.html#process_process_exit_code

process.kill(process.pid)

      



http://nodejs.org/api/process.html#process_process_kill_pid_signal

Both exits from the process.

+2


source







All Articles