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

213
Visualizações
Connection to nodejs (express) refused

I’m a long term programmer, but haven’t used nodejs much in my code. Now I need to use it in my current code and I’ve ran into a problem that I can’t seem to figure out myself, I have googled a lot but nothing seem to fix it.

I am trying to get my website to connect to the nodejs server running on same host.

If I visit the url in my browser, it works fine (http://localhost:6857/socket.io/?EIO=4&transport=polling) and I see this respond

0{"sid":"s_v860SbNO4toknPAAAA","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":20000}

But when I try to connect thru the website, I just get

GET http://localhost:6857/socket.io/?EIO=3&transport=polling&t=N_gL_HZ net::ERR_CONNECTION_REFUSED

Can someone guide my in the right direction for how to fix this, so I can begin using nodejs inside my website?

This is my server.js

// use express
var express = require("express");
 
// create instance of express
var app = express();


 
// use http with instance of express
var http = require("http").createServer(app);

// start the server
var port = 6857;
http.listen(port, '0.0.0.0', function () {
    console.log("Listening to port " + port);
});

// create socket instance with http
var io = require("socket.io")(http);

// add listener for new connection
io.on("connection", function (socket) {
    // this is socket for each user
    console.log("User connected", socket.id);
});

io.on("connect_error", (err) => {
  console.log(`connect_error due to ${err.message}`);
});

And this is my JS code inside my website

<script>
    var server = "http://localhost:6857/";
    var io = io(server);
</script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Socket IO requires you to enable CORS explicitly - Thus why you get the error stated above.

To enable CORS, please see the following link

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