0

I'm trying to make Express listen to different domains on my local machine. But when I do

app.listen(80, "127.0.0.1");

I get the following error: Error: listen EACCES: permission denied 127.0.0.1:80. I tried with sudo and with other domains (127.0.0.2) but ended up with the same error message.

Is it even possible to do this with Express only? Do I miss something here?

Complete stack trace:

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

Error: listen EACCES: permission denied 127.0.0.1:80
    at Server.setupListenHandle [as _listen2] (net.js:1301:21)
    at listenInCluster (net.js:1366:12)
    at doListen (net.js:1503:7)
    at processTicksAndRejections (internal/process/task_queues.js:81:21)
Emitted 'error' event on Server instance at:
    at emitErrorNT (net.js:1345:8)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  code: 'EACCES',
  errno: -13,
  syscall: 'listen',
  address: '127.0.0.1',
  port: 80
}
nathaner
  • 463
  • 4
  • 18
  • 1
    Only `root` is allowed to listen at privileged ports (under 1024). Running under sudo as root should fix this. If you are still getting the same error, you are likely doing sudo wrong. If you are getting another error, please post that error (likely you have Apache or Nginx or such already bound to 80; you can't have two processes listening on the same port). – Amadan Jul 16 '21 at 21:41
  • 1
    Where's the rest of the error? Also, check whether something else is already running on port 80 (like apache, nginx, etc). And finally, app.listen does not need an ip address, using `app.listen(80)` runs localhost by definition. – Mike 'Pomax' Kamermans Jul 16 '21 at 21:41
  • I have exactly the same error message with `sudo` by doing a `sudo npm run myscriptname`. I don't have anything running on these addresses. I do want to specify the `host` in `app.listen` as I want to deploy on 2 different domains in my local env. – nathaner Jul 16 '21 at 21:51
  • Does this answer your question? [Node.js + Express: app won't start listening on port 80](https://stackoverflow.com/questions/7929563/node-js-express-app-wont-start-listening-on-port-80) – hjrshng Jul 16 '21 at 22:33
  • No unfortunately – nathaner Jul 17 '21 at 08:11

0 Answers0