错误:在nodejs

时间:2016-03-24 12:29:11

标签: javascript node.js

我使用that

在sublime中创建了javascript构建系统

然后我使用该代码运行服务器

var server = require('http');

function engine(request, response){
    response.writeHead(200,  {'Content-Type': 'text/plain'});
    response.end("Hello");
}

server.createServer(engine).listen(3000);

但是当我进行更改并且例如将Hello更改为Hello World并刷新浏览器时,它没有任何意义,当我尝试重新运行时(\ n) 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]

我知道因为3000端口正在使用但是如何停止该端口再运行新代码?

我在node.js上很新,所以请随意提出任何建议

5 个答案:

答案 0 :(得分:0)

如何运行nodejs实现?

您可以尝试使用包nodemon

npm install -g nodemon

现在,您可以通过在目录中键入nodemon来启动节点应用程序。 如果您现在更改并保存文件,服务器将自动重新启动您的服务器。

如果您不想使用nodemon,请使用ctrl + c

关闭服务器

答案 1 :(得分:-1)

server.createServer(engine).listen(3000);

这就是您说端口所在的位置,您可以将端口更改为任何其他端口。

要重新运行代码,我认为您使用控制台,可以按ctrl + C停止进程并使用node nameOfYoursServerFile.js再次运行

答案 2 :(得分:-1)

使用lsof -w -n -i tcp:3000查找3000上流程的PID值 然后,使用kill -9 PID切换PID并使用第一个命令返回的PID来终止它。

答案 3 :(得分:-1)

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 

答案 4 :(得分:-1)

Ctrl+C前台进程或使用pidof node查找正在运行的进程ID,然后将其删除(kill pid)。即使您使用forever或在后台以其他方式运行,这也可以。

相关问题