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

111
Visualizações
Connect servers running on two ports

I'm a big newbie when it comes to JS and web apps. I have two servers running on my computer on two different ports (5000 and 5001). The 5000 server provides a route that needs to communicate with the server on port 5001, and I can't seem to make that work.

I'm using express.js and xhr2 for the HTTP requests. There seem to be a problem with my url. Am I not supposed to look for the port at the 0.0.0.0 address ? (I have tried using the localhost one as well and it's not working).

You can find below an example of such a route. Thanks for your help !

app.get('/user', (req, res) => {
   var url = "0.0.0.0:5001/user"
   var XMLHttpRequest = require('xhr2')
   var xhr = new XMLHttpRequest();
   xhr.open("GET", url, true);
   console.log(url)
   xhr.addEventListener('readystatechange', function() {
           if (xhr.status == 200) {
               res.status(200).send(xhr.responseText)
           }
       });
   xhr.send();
})
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

try localhost:port or 127.0.0.1:port, maybe that works

edit: yea you forgot the schema, try "http://localhost:5001/user" or the same with https instead. (credit @Heiko Theiße)

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