Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

475
Visualizações
NodeJs Error: Port already in use:3000 using socket.io and express

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.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

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

about 4 years ago · Juan Pablo Isaza Relatório

0

free your 3000 port:

Linux: fuser -k 3000/tcp

about 4 years ago · Juan Pablo Isaza Relatório

0

According to this question on glitch.com's forums you might have two services listening to the same port, but that doesn't seem to be the case.

You should also be able to change the default listening port by setting the PORT environment variable in your .env file if you have one. Trying a different port should solve the problem

EDIT: Apparently the problem could be the initial configuration of the server, you can try setting everything up like this:

const app = require('express')();
const server = require('http').createServer(app); <--
const io = require('socket.io')(server);
io.on('connection', () => { /* your code */ });

server.listen(process.env.PORT, () => {/* your code */});

(Got this from socket.io github page)

If this doesn't work either you should try asking on glitch.com's support forums, one of their technicians will help you better troubleshoot your problem, they have all the necessary tools

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda