Reputation: 435
The question may sound clumsy because I don't know how to put it in words. Please take a look at this example:
//PHP
<?php
die( "The PHP process stops here. The PHP is still running" );
insert_into_database_someinfo(); //This function will not be executed
?>
My question is: What is equivalent to die() or exit() in PHP for Nodejs, without stopping the whole current nodejs server? I found the owner of this link having the same issue but the suggestion of using process.exit()
is not appropriate.
process.exit()
will stop the entire server.
The following code attempts to output to the browser, but unlike PHP die()
, this will continue onto the next lines
req.end( 'This is an output to the browser' );
insert_into_database_someinfo(); //This function will still be executed.
I would consider this to be somewhat comparable to echo()
in PHP, because everything keeps going. I would like to output info, then stop the process there (just the current request, not the whole nodejs server).
Please advise.
Upvotes: 0
Views: 809
Reputation: 382264
Insert a return
to stop the execution of your function :
if (nogood) {
req.end( 'This is an output to the browser' );
return;
}
insert_into_database_someinfo();
Upvotes: 1