[英]Error: listen EADDRINUSE in nodejs
I've created javascript build system in sublime using that 我已经使用它在Sublime中创建了javascript构建系统
Then I run server using that code 然后我使用该代码运行服务器
var server = require('http');
function engine(request, response){
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end("Hello");
}
server.createServer(engine).listen(3000);
but when I'll make change and for example will change Hello
to Hello World
and refresh browser it doesn't make any sense and when I'm trying rerun (f7) it throws an exception 但是当我进行更改时,例如将
Hello
更改为Hello World
并刷新浏览器,这没有任何意义,当我尝试重新运行(f7)时会抛出异常
events.js:141
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::3000
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at Server._listen2 (net.js:1231:14)
at listen (net.js:1267:10)
at Server.listen (net.js:1363:5)
at Object.<anonymous> (C:\Users\gsiradze\Desktop\nodejs\script1.js:4:8)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
[Finished in 0.1s]
I know that it's because of 3000 port is in use but how can I stop that port an then run the new code? 我知道这是因为正在使用3000端口,但是如何停止该端口然后运行新代码?
I'm pretty new at node.js, so feel free to give any suggestion 我是node.js的新手,请随时提出任何建议
How do you run the nodejs implementation? 您如何运行nodejs实现?
You could try to use the package nodemon 您可以尝试使用nodemon软件包
npm install -g nodemon
Now you can start your node application by typing nodemon in the directory. 现在,您可以通过在目录中键入nodemon来启动节点应用程序。 If you change and save your file now, the server will automatically restart your server.
如果您现在更改并保存文件,服务器将自动重新启动服务器。
If you dont want to use nodemon, shut down the server with ctrl+c 如果您不想使用nodemon,请使用ctrl + c关闭服务器
server.createServer(engine).listen(3000);
that's where you say where port is located, you can change port to any other one. 那就是您说端口所在的位置,您可以将端口更改为任何其他端口。
To rerun your code, I take it you use console you can press ctrl+C to stop process and run it again with node nameOfYoursServerFile.js 要重新运行代码,请使用控制台,您可以按ctrl + C停止进程,然后使用节点名称OfYoursServerFile.js再次运行它
使用lsof -w -n -i tcp:3000
在3000上找到您的进程的PID是什么,然后,使用kill -9 PID
切换PID
并使用第一个命令返回的PID来kill -9 PID
它。
You need to get the PID of node service
You can do that by running this command on your terminal
ps aux | grep node
it will give you id of running node process
and the you can use
kill -9 <id of node process>
to stop node process and then try again to run your node server
Either Ctrl+C
the foreground process or find your running process's ID by using pidof node
and then killing it ( kill pid
). Ctrl+C
前台进程,或者使用pidof node
找到正在运行的进程的ID,然后将其kill pid
( kill pid
)。 Even if you are running with forever
or in the background some other way, this will work. 即使您
forever
运行或在后台以其他方式运行,这也将起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.