Home > other >  Address already in use with Socket.io in Express
Address already in use with Socket.io in Express

Time:09-10

I'm trying to use websockets in my app but I'm not able to get Socket.io to connect to my server. Whenever I run the code below, I get this error:

Error: listen EADDRINUSE: address already in use :::3000

I've tried looking up some solutions, and I found that there's no other processes running on this port, so the issue has to be within the project. What could I be doing wrong here?

const express = require("express");
const mongoose = require("mongoose");
const app = express();
const { createServer } = require("http");
const httpServer = createServer(app);

const socketIO = require("socket.io")(3000, { cors: { origin: "*" } });
socketIO.on("connection", (socket) => {
    console.log("connected");
});

const port = 3000;

const startServer = () => {
    httpServer.listen(port);
    console.log(`Listening on port ${port}            
  • Related