抱歉,如果这里的问题的某些方面不清楚,因为我是新的节点和JavaScript。详情请咨询
我有一个使用socketio连接到firebase的node应用程序。当应用程序部署在heroku上时,我得到以下错误:
Error [ERR_SERVER_ALREADY_LISTEN]: Listen method has been called more than once without closing.
Nov 01 19:57:38 app/web.1: at Server.listen (net.js:1446:11)
Nov 01 19:57:38 app/web.1: at exports.default (/app/dist/server.js:8226:11)
Nov 01 19:57:38 app/web.1: at Object.<anonymous> (/app/dist/server.js:191:21)
Nov 01 19:57:38 app/web.1: at __webpack_require__ (/app/dist/server.js:20:30)
Nov 01 19:57:38 app/web.1: at Object.<anonymous> (/app/dist/server.js:47:19)
Nov 01 19:57:38 app/web.1: at __webpack_require__ (/app/dist/server.js:20:30)
Nov 01 19:57:38 app/web.1: at /app/dist/server.js:40:18
Nov 01 19:57:38 app/web.1: at Object.<anonymous> (/app/dist/server.js:43:10)
Nov 01 19:57:38 app/web.1: at Module._compile (module.js:641:30)
Nov 01 19:57:38 app/web.1: at Object.Module._extensions..js (module.js:652:10)
Nov 01 19:57:38 app/web.1: /app/dist/server.js:212
Nov 01 19:57:38 app/web.1: throw error;
错误的描述在这个链接上:
https://nodejs.org/api/all.html#errors_err_server_already_listen
我的server.js上的监听代码如下所示:
const server = http.createServer(app).listen(port)
知道为什么会出现这个错误吗?如果监听失败,我应该关闭服务器吗?如果是,我该如何做?
谢谢
1条答案
按热度按时间t2a7ltrp1#
我的错。我很困惑,因为错误不是发生在我的mac上。答案就在错误本身。当listen方法被调用两次时发生错误。第二个电话是在另一个模块。