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

369
Visualizações
How to get the link of the created server in the http.createServer() function?

How to get the link of the created server in the http.createServer() function?

I am trying to use the http package from node.js and use the createServer() function, then I want to print the server's link with the port, like this:

const createServer = http.createServer();
const server = createServer.listen(port);

And then get the link from the createServer variable like http://localhost or from a repl.it/replit.com link . this is my code in JS:

const port = 1234;
const createServer = http.createServer();
const server = createServer.listen(port);
const websocket = new web({ httpServer: server });

console.log(createServer); // This doesnt print the server link
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can get the information about the server by calling server.address():

console.dir(server.address());

//{ address: '::', family: 'IPv6', port: 1234 }

Since you didn't specify a host when creating the server, the default one will be used which according to the documentation:

If host is omitted, the server will accept connections on the unspecified IPv6 address (::) when IPv6 is available, or the unspecified IPv4 address (0.0.0.0) otherwise.

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