如何解决运行节点服务器错误

时间:2017-08-15 07:26:55

标签: node.js

运行节点服务器时,我一直面临以下错误,但以前的代码工作正常。任何专家都可以解决这个问题吗?

以下是server.js的错误部分

    try {
        app.listen(port, function(){
            console.log('Server started on port'+port);
        })
    } catch (e) {
        console.log('There was an error', e);
    }

-------------------------------error---------------------------------------
PS C:\Users\User\WebstormProjects\myapp> nodemon server
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node server app.js`
events.js:182
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE :::3000
    at Object.exports._errnoException (util.js:1024:11)
    at exports._exceptionWithHostPort (util.js:1047:20)
    at Server.setupListenHandle [as _listen2] (net.js:1319:14)
    at listenInCluster (net.js:1367:12)
    at Server.listen (net.js:1467:7)
    at Function.listen (C:\Users\User\WebstormProjects\myapp\node_modules\express\lib\application.js:618:24)
    at Object.<anonymous> (C:\Users\User\WebstormProjects\myapp\server.js:52:9)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
[nodemon] app crashed - waiting for file changes before starting...

2 个答案:

答案 0 :(得分:-1)

另一个应用程序已经在使用端口3000.您可以使用另一个端口启动它。

答案 1 :(得分:-1)

你的应用程序正在运行,也许你只是启动了两次,你可以试试skill node&amp;再次启动它,或将变量端口更改为3001