node.js 如何在 Windows 上退出 nodemon

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17612653/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 15:01:09  来源:igfitidea点击:

How to exit nodemon on a windows

node.js

提问by Johan Hallager

I′am on a windows machine, and I understand that it is a little different here.

我在 Windows 机器上,我知道这里有点不同。

The problem is that I can't find any information on how I stop, kill or exit nodemon.

问题是我找不到有关如何停止、杀死或退出 nodemon 的任何信息。

采纳答案by kentcdodds

For purposes of completeness, The correct answer is press Ctrl+ C. Or you could also find it in task manager and kill it. This applies to pretty much anything on the command line.

为完整起见,正确答案是按Ctrl+ C。或者你也可以在任务管理器中找到它并杀死它。这几乎适用于命令行上的任何内容。

回答by Brian

My experience here is that Ctrl+C leaves a node instance running in the background. If you want to kill the stack, when you try to restart 'nodemon server.js' or just 'node server.js' for that matter, you will get an EADDRINUSE error because the old node server has the port tied up. You have to find it by using ps -W | grep nodein the terminal window, because the task manager wont show it. Also you can kill it with the process ID (PID) with taskkill. The /F is the 'force' parameter. Here we will kill the task with PID 7528.

我的经验是 Ctrl+C 会留下一个在后台运行的节点实例。如果您想终止堆栈,当您尝试重新启动“nodemon server.js”或“node server.js”时,您将收到一个 EADDRINUSE 错误,因为旧节点服务器的端口被绑定。您必须ps -W | grep node在终端窗口中使用才能找到它,因为任务管理器不会显示它。您也可以使用 taskkill 使用进程 ID (PID) 杀死它。/F 是“力”参数。在这里,我们将终止 PID 为 7528 的任务。

$ taskkill /F /PID 7528

Then check ps -W | grep node again, and the node server should be gone, and the server will launch again.

然后检查 ps -W | 再次 grep 节点,节点服务器应该消失了,服务器将再次启动。

Their docs show a few tricks on intercepting the shutdown command, but since they use a 'rs' command to restart, they could add a 'kill' command to shutdown the daemon.

他们的文档展示了一些拦截关闭命令的技巧,但由于他们使用“rs”命令重新启动,因此他们可以添加“kill”命令来关闭守护程序。

Brian

布赖恩

回答by roger

I used git bash on window and I couldn't terminate the nodemon process with ctr+ c, so I would terminate the node process on the task manager to use the same port. Later I found on githubto why nodemondoesn't terminate in git bash. Anywaypowershellshould be use instead, after ctr+ cit will ask either to terminate batch job or not. This action will clear the process and stop nodemon.

我在窗口上使用了 git bash 并且我无法用ctr+终止 nodemon 进程c,所以我会终止任务管理器上的节点进程以使用相同的端口。后来我在github上发现为什么nodemon不以git bash. 无论如何powershell都应该使用,在ctr+之后c它会询问是否终止批处理作业。此操作将清除进程并停止 nodemon。

回答by t.howell

I had issues with this until I ran command prompt as an administrator. Then Ctrl+ Cworked.

在我以管理员身份运行命令提示符之前,我遇到了这个问题。然后Ctrl+C工作。

EDIT:Sorry, the above worked once and then stopped working. I did end up finding this article: http://www.wisdomofjim.com/blog/how-kill-running-nodejs-processes-in-windows. The command provided here (taskkill /im node.exe /F) works consistently for me on Windows, when I run it in a new command prompt window.

编辑:对不起,以上工作一次,然后停止工作。我最终找到了这篇文章:http: //www.wisdomofjim.com/blog/how-kill-running-nodejs-processes-in-windows。当我在新的命令提示符窗口中运行它时,此处提供的命令 (taskkill /im node.exe /F) 在 Windows 上始终适用于我。

回答by Pratik Adhikari

Press Ctrl + C to exit from Nodemon on windows. If that does not work, simply end the task from task manager and run it again.

在 Windows 上按 Ctrl + C 退出 Nodemon。如果这不起作用,只需从任务管理器结束任务并再次运行它。

回答by Akhilesh Sinha

type .exit (it worked in my case)

输入 .exit (它在我的情况下有效)