首页 > 解决方案 > 当多个开发人员在 Node JS 中使用相同的端口时,为什么应用程序会崩溃

问题描述

我们有一个用于开发的集中式服务器。我们已经安装了“nodemon”来自动刷新服务器。现在多个开发人员使用 CLI 从他们的本地服务器访问服务器。当 Developer-1 运行命令“nodemon app.js”时,服务器运行良好。但在那之后,当 Developer-2 运行相同的命令时,他得到以下错误。

events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::1111
    at Server.setupListenHandle [as _listen2] (net.js:1277:14)
    at listenInCluster (net.js:1325:12)
    at Server.listen (net.js:1412:7)
    at Function.listen (/home/john/sites/www/Tastii-Dev1-Portal/node_modules/express/lib/application.js:618:24)
    at Object.<anonymous> (/home/john/sites/www/Tastii-Dev1-Portal/app.js:41:5)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
Emitted 'error' event at:
    at emitErrorNT (net.js:1304:8)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
[nodemon] app crashed - waiting for file changes before starting...

标签: node.jsnode-modules

解决方案


推荐阅读