这个问题可能听起来很笨拙,因为我不知道如何用语言表达。请看一下这个例子:
//PHP
<?php
die( "The PHP process stops here. The PHP is still running" );
insert_into_database_someinfo(); //This function will not be executed
?>
我的问题是:什么相当于 Nodejs PHP 中的 die() 或 exit(),无需停止整个当前的 Nodejs 服务器?我找到了这个link的主人遇到同样的问题,但使用 process.exit()
的建议不合适。
process.exit()
将停止整个服务器。
以下代码尝试输出到浏览器,但与 PHP die()
不同,这将继续到下一行
req.end( 'This is an output to the browser' );
insert_into_database_someinfo(); //This function will still be executed.
我认为这有点类似于 PHP 中的 echo()
,因为一切都在继续。我想输出信息,然后在那里停止进程(只是当前请求,而不是整个nodejs服务器)。
请指教。
最佳答案
插入返回
以停止函数的执行:
if (nogood) {
req.end( 'This is an output to the browser' );
return;
}
insert_into_database_someinfo();
关于javascript - 如何仅停止当前页面进程,而不停止整个 NodeJS 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24548650/