Question

Unable to start nodejs application

Posted March 14, 2021 689 views
Node.js

I am trying to start nodejs server and receiving the following error no matter which port I choose to listen from:

root@nodejs-s-1vcpu-1gb-fra1-01:~/SalahTimes.PL# node server.js
events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use :::80
    at Server.setupListenHandle [as _listen2] (net.js:1313:16)
    at listenInCluster (net.js:1361:12)
    at Server.listen (net.js:1447:7)
    at Function.listen (/root/SalahTimes.PL/node_modules/express/lib/application.js:618:24)
    at Object.<anonymous> (/root/SalahTimes.PL/server.js:14:5)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
Emitted 'error' event on Server instance at:
    at emitErrorNT (net.js:1340:8)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  code: 'EADDRINUSE',
  errno: 'EADDRINUSE',
  syscall: 'listen',
  address: '::',
  port: 80
}
edited by bobbyiliev

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi there,

It looks like port 80 is already being used by another service. You can check which service exactly by running the following command:

netstat -plant | grep 80

You can not have more than 1 service listening on the same port.

What you could do is change the Node application port to 8080 for example so that it could start as normal.

I would also suggest following the steps here on how to prepare your Node application for production:

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-20-04

Hope that this helps!
Regards,
Bobby

by Lisa Tagliaferri
by Kathleen Juell
Node.js is an open-source JavaScript runtime environment for building server-side and networking applications. The platform runs on Linux, macOS, FreeBSD, and Windows. Though you can run Node.js applications at the command line, this tutorial will…