用于退出的命令是什么?(即终止Node.js进程)


当前回答

ctrl+C终止当前进程ctrl+C两次是退出REPL shellctrl+c退出REPL SHELL

其他回答

我可以通过键入taskkill-F-IM node.exe,让我的所有节点进程直接从Windows 10上的Git Bash shell中消亡-这将立即结束我计算机上的所有节点过程。我发现我也可以使用taskkill//F//IM node.exe。不确定为什么-和//在这种情况下都有效。希望这有帮助!

从代码中,您可以使用process.ext([errorcode]),其中[errorcode]是可选整数(0是表示成功的默认值)。

如果使用的是Read-Eval打印循环(REPL),则可以使用Ctrl+D或键入.ext

或者,在Windows或Linux上,可以使用Ctrl+C、Ctrl+C

在Mac上,命令为Ctrl+Z,Ctrl+Z

正如@Dominic所指出的,抛出未捕获的错误是更好的做法,而不是调用process.ext([code]):process.exitCode=1;抛出新错误(“我的模块xx条件失败”);

在命令行中,.ext是您想要的:

$ node
> .exit
$

它记录在REPL文档中。REPL(Read Eval Print Loop)是Node命令行的名称。

在正常程序中,使用process.ext([code])。

退出

let exitCode = 1;
process.exit(exitCode)

有用的退出代码

1 - Catchall for general errors
2 - Misuse of shell builtins (according to Bash documentation)
126 - Command invoked cannot execute
127 - “command not found”
128 - Invalid argument to exit
128+n - Fatal error signal “n”
130 - Script terminated by Control-C
255\* - Exit status out of range