Home > Back-end >  NodeJs Error: Port already in use:3000 using socket.io and express
NodeJs Error: Port already in use:3000 using socket.io and express

Time:02-10

I'm making a node.js application that uses socket.io and express.

The code looks like this-

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 container all the html files for the website.

Now,when I run it locally on my pc,it works fine But when I deployed it on the glitch.com servers,i get this error:

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

As far as i know,3000 is the only available port in glitch and I cannot use another port.

Also,the questions on stack overflow related to this topic doesn't help me since most of the answers are related to killing the running tasks themselves and I don't have permission to do so on the server.

CodePudding user response:

This often happens when your server is still running in error, try switching listening to 3001 and see if there is still the error

CodePudding user response:

free your 3000 port:

Linux: fuser -k 3000/tcp

  • Related