从命令行停止node.js程序 [英] Stop node.js program from command line
本文介绍了从命令行停止node.js程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的TCP服务器侦听端口。
I have a simple TCP server that listens on a port.
var net = require("net");
var server = net.createServer(function(socket) {
socket.end("Hello!\n");
});
server.listen(7777);
我以节点server.js
然后在Mac上使用Ctrl + Z关闭它。当我尝试使用节点server.js
再次运行它时,我收到此错误消息:
I start it with node server.js
and then close it with Ctrl + Z on Mac. When I try to run it again with node server.js
I get this error message:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: listen EADDRINUSE
at errnoException (net.js:670:11)
at Array.0 (net.js:771:26)
at EventEmitter._tickCallback (node.js:192:41)
b $ b
我是以错误的方式关闭程序吗?
Am I closing the program the wrong way? How can I prevent this from happening?
推荐答案
要结束程序,应该使用 Ctrl + C SIGINT ,这允许程序正常结束,从任何正在侦听的端口解除绑定。
To end the program, you should be using Ctrl + C. If you do that, it sends SIGINT
, which allows the program to end gracefully, unbinding from any ports it is listening on.
另请参阅: http://superuser.com/a/262948/48624
这篇关于从命令行停止node.js程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文