Error: Port already in use:3000 in node.js using socket io and express

Hello everyone!
I was making a node.js application that includes express and socket.io.

The code I’m using is here-

const express=require('express');
const app=express();
const http=require('http').Server(app);
app.use(express.static('public'));

const io=require('socket.io')(http,{
  cors:{origin:'*'}
});

http.listen(3000,()=>{
  console.log('listening to port 3000');
});

//when connection made 
io.on('connection',(socket)=>{
  console.log('connection made!');
});

Here,public is a folder containing some html files
and I’m getting the error-

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

Basically,a error saying the post 3000 is in use already. Now,as far as i know,port 3000 is available globally
And this code when tested on my pc locally works fine.

Any help regarding this will greatly be appreciated!

Glitch serves projects at port 3000, which might be conflicting with the socket’s port.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.