且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Node.js中退出

更新时间:2023-02-14 13:09:06

调用全局 process 对象的 exit 方法:

Call the global process object's exit method:

process.exit()

从文档中获取:

process.exit([code])

以指定的code结束进程.如果省略,则退出使用成功"代码0.

process.exit([code])

Ends the process with the specified code. If omitted, exit uses the 'success' code 0.

要以失败"代码退出:

process.exit(1);

执行节点的外壳应该将退出代码显示为1.

The shell that executed node should see the exit code as 1.