如何退出node.js

How to exit in Node.js

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


(P)呼叫全球EDOCX1号音标异形物体EDOCX1号音标(p)字母名称(P)From the Docs:(p)布尔奇1


(P)From the official node js.org documentation:(p)字母名称(P)Ends the process with the specified code.如果遗漏,退出使用"成功"代码0。(p)(P)3.To exit with a'failure'code:(p)字母名称


(P)Just a note that using EDOCX1 English 12 is not recommended practice.(p)布尔奇1


(P)如果你在一个单终端或Windows command line,并想要退出节点repl,either…(p)

  • Press trl+dcabd twice,or
  • Type EDOCX1(音标2)和Press Enter,or
  • Press trl+dabbd at the start of a line(UNIX only)


(P)从指令线,EDOCX1英文第2个字母是你想要的:(p)字母名称(P)It's documented in the repl docs.Repl(read-eval-print-loop)is what the node command line is called.(p)(P)从一个正常的程序,使用字母名称4。(p)


(P)It depends on the reason why you're willing to exit node.js process,but in any case EDOCX1 substantive 14 is the last option to consider.A quote from documentation:(p)布尔奇1(P)Let's cover possible reasons why you might be willing to exit node.js process and why you should avoid EDOCX1.(p)Case 1-Execution complete(Command line script)(P)如果Script has reached its end and node interpreter doesn't exit,it indicates that some async operations are still pending.It's wrong to force process end with EDOCX1 sil文14 at this point.It's better to try to understand what is holding your script from exiting in expected way.And when you settle this,you can use EDOCX1 English 17 to return any result to calling process.(p)案例2-由于外部签字而终止(Sigint/Sigterm/Other)(P)For example,if you're willing to grateful shut down an express app.Unlike command line script,express app keeps running infinely,waiting for new requests.EDOCX1 14 will be a bad option here because it's going to interrupt all requests which are in pipeline.and some of them might be non-idemptent(Update,delete).如果这些要求是复杂的,或者不是在服务领域,那么客户就永远不知道,这可能是客户与服务器之间数据不一致的原因。The only good solution is to tell http://server to stop accepting new requests and wait for pending ones to finish with EDOCX1.(p)字母名称(P)如果它仍然不存在——见案例1。(p)案例3内部错误(P)这是一个错误,你会得到一个独特的格式化斯塔克跟踪和错误的信息。Upper Levels of Code can always decide if they can handle mistake(EDOCX1 English 21)or let it crash the process.在另一边,EDOCX1的音标22将结束过程沉默,并将是不可能从这个。它可能是唯一的"好处"的EDOCX1的音效14,你可以肯定这一过程将被完成。(p)


repl(命令行)

  • 按两次ctrl + c

  • 键入.exit并按Enter键

脚本文件

1
process.exit(code)

当不再挂起异步操作时,节点通常退出,代码为0。

应使用process.exit(1)退出并返回故障代码,这将使我们可以推断该节点没有正常关闭,并被强制关闭。

还有其他出口代码,比如

3-内部javascript分析错误(非常罕见)

5-V8 javascript引擎中出现致命错误

9-无效参数

有关完整列表,请参见节点退出代码


(P)I have an application which I wanted to:(p)

  • Send an email to the user
  • 有错误代码的退出
  • (P)I had to Hook EDOCX1 penographic 9 to an EDOCX1 penographic 1 event handler,or else the mail will not be sent since the original calling EDOCX1 penographic 9 directly kills asynchronous events.(p)字母名称


    (P)As@Dominic pointed out,throwing an uncaught mistake is better practice instead of calling process.exit():字母名称(p)


    (P)From code you can use EDOCX1 penographic 5 where EDOCX1 penographic 6 is an optional integer(EDOCX1 pental 7)is the default to indicate success.(p)(P)如果你使用了Read eval print loop(repl),你可以使用trl+dabd,或Type EDOCX1(p)(P)Alternatively,on windows or linux you can use trl+dcabd,trl+dcabd(p)(P)On Mac the Command is dctrl+dzdctrl+dszabbd(p)


    按两次ctrl + c。或.exit

    1
    2
    3
    >
    (To exit, press ^C again or type .exit)
    >


    (P)成功,成功(p)字母名称(P)用户退出代码(p)字母名称


    通过输入taskkill -F -IM node.exe,我可以让所有节点进程直接从Windows10上的git bash shell中死掉——这将立即结束我计算机上的所有节点进程。我发现我也可以使用taskkill //F //IM node.exe。不知道为什么-//都在这种情况下工作。希望这有帮助!


    命令行

    按Ctrl+C两次

    键入.exit并按Enter键

    脚本文件

    1
    process.exit(code)


    打开正在运行节点应用程序的命令行终端,然后按ctrl+c

    如果要从代码中退出节点JS应用程序,

    1
    2
    process.exit(); // graceful termination
    process.exit(1); // non graceful termination

    如果要退出node js应用程序,则写入

    1
    process.exit(1)

    在您的代码中


    您可以使用process.exit([代码])函数。

    如果要退出而不出现"失败",则使用代码0

    1
    process.exit(0);

    要退出并显示"失败"代码1,您可以运行:

    1
    process.exit(1);

    失败的"失败"代码特定于应用程序。因此,您可以使用自己的约定。