Question + node.js + apache port error

I created an application I set up using apache on my ubuntu server.

My IP address is

Currently, apache is listening on port 80 and port 8080.

My app is live and can be viewed at either port.

I am using node.js to run the server-side at port 8000 with server.js

I cannot run server.js and apache on the same port.

When I try to change the port on server.js to 8080 or 80 I run into the following error:

      throw er; // Unhandled 'error' event

Error: listen EADDRINUSE: address already in use :::8080
    at Server.setupListenHandle [as _listen2] (net.js:1280:14)
    at listenInCluster (net.js:1328:12)
    at Server.listen (net.js:1415:7)
    at Object.<anonymous> (/root/server.js:17:8)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
Emitted 'error' event at:
    at emitErrorNT (net.js:1307:8)
    at pro```code```cess._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

How do I connect my application to using the same port?

Do I need to use a reverse proxy or is there a more simple way?

Here is my server.js code:

const server = require('http').createServer()
const io = require('')(server, { 
    cors: { 
         origin: '*', 
         methods: ["GET", "POST"],
         allowedHeaders: ["my-custom-header"],
         credentials: true

const port = 8000;

// Listen for incoming connections
server.listen(port, (err) => {
    if (err) throw err
    console.log(`Listening on port ${port}`);

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer