我正在学习Heroku文档(https://devcenter.heroku.com/articles/getting-started-with-nodejs)中的教程,并在运行命令时遇到了问题:
% heroku local web
在Mac(M1)上,虽然教程的第一部分都很顺利,但在 * 本地运行应用程序 * 一节中,我得到了以下结果(而不是应该发生的结果):
myveryname@Me-MacBook-Air node-js-getting-started % heroku local web
[OKAY] Loaded ENV .env File as KEY=VALUE Format
2:20:52 PM web.1 | > node-js-getting-started@0.3.0 start
2:20:52 PM web.1 | > node index.js
2:20:52 PM web.1 | node:events:491
2:20:52 PM web.1 | throw er; // Unhandled 'error' event
2:20:52 PM web.1 | ^
2:20:52 PM web.1 | Error: listen EADDRINUSE: address already in use :::5000
2:20:52 PM web.1 | at Server.setupListenHandle [as _listen2] (node:net:1432:16)
2:20:52 PM web.1 | at listenInCluster (node:net:1480:12)
2:20:52 PM web.1 | at Server.listen (node:net:1568:7)
2:20:52 PM web.1 | at Function.listen (/Users/myveryname/Documents/Heroku/node-js-getting-started/node_modules/express/lib/application.js:635:24)
2:20:52 PM web.1 | at Object.<anonymous> (/Users/myveryname/Documents/Heroku/node-js-getting-started/index.js:10:4)
2:20:52 PM web.1 | at Module._compile (node:internal/modules/cjs/loader:1126:14)
2:20:52 PM web.1 | at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
2:20:52 PM web.1 | at Module.load (node:internal/modules/cjs/loader:1004:32)
2:20:52 PM web.1 | at Function.Module._load (node:internal/modules/cjs/loader:839:12)
2:20:52 PM web.1 | at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
2:20:52 PM web.1 | Emitted 'error' event on Server instance at:
2:20:52 PM web.1 | at emitErrorNT (node:net:1459:8)
2:20:52 PM web.1 | at processTicksAndRejections (node:internal/process/task_queues:83:21) {
2:20:52 PM web.1 | code: 'EADDRINUSE',
2:20:52 PM web.1 | errno: -48,
2:20:52 PM web.1 | syscall: 'listen',
2:20:52 PM web.1 | address: '::',
2:20:52 PM web.1 | port: 5000
2:20:52 PM web.1 | }
[DONE] Killing all processes with signal SIGINT
2:20:52 PM web.1 Exited with exit code null
myveryname@Me-MacBook-Air node-js-getting-started %
在网上搜索似乎表明Mac可能会自己使用5000端口。当我在网页浏览器中查看http://localhost:5000/时,5000端口似乎确实有点忙碌(尽管页面显示完全是白色)。但我不知道它在做什么。即使我重新启动计算机,情况也不会改变。
我一定不是唯一一个碰到这个问题的人。那么,处理这种情况并能够继续本教程结尾的正确方法是什么呢?
1条答案
按热度按时间s1ag04yj1#
在mac上,Air Play控制中心监听端口5000。您可以禁用airplay接收器以释放该端口,也可以将代码上的端口更改为类似5001的值
您也可以运行此命令
lsof -i :5000
来检查哪个进程正在使用5000端口参考:https://developer.apple.com/forums/thread/682332