node.jsherokuheroku-cli

Command not working in the middle of a Heroku tutorial


I am following a tutorial in Heroku documentation (https://devcenter.heroku.com/articles/getting-started-with-nodejs) and hit the problem hereafter, when running the command:

% heroku local web

On a Mac (M1), though all the first part of the tutorial went fine, in the section Run the app locally, this is what I get (not what is supposed to happen):

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 % 

Searching the net seems to suggest that Mac may make use of the 5000 port on its own. When I look at http://localhost:5000/ in my web browser, it looks like the port 5000 is indeed somewhat busy (though the page shows completely white). But I have no idea what it is doing. And even if I restart the computer that does not change.

I must not be the only one to have hit this issue. So what is the correct way to handle this situation and be able to continue with the end of the tutorial?


Solution

  • On mac Air Play Control Center listens on port 5000. You can disable airplay receiver to release the port or you can change the port on your code to something like 5001

    you can also run this command lsof -i :5000 to check which process is using 5000 port

    Reference:https://developer.apple.com/forums/thread/682332