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

148
Visualizações
NodeJS websocket not responding properly

I'm extremely new to any kind of web-development so sorry in before-hand if what I write makes no sense. I'm working on a website that can get and post data through a website to a machine. (Client/Browser <-> Webserver <-> Machine). I'm having a problem though opening a websocket to be used by the Webserver <-> Machine connection. I use Javascript since I couldn't find any other viable solution to make this work. My code looks like this:

const WebSocket = require('ws');
const webSocketServer = new WebSocket.Server({port: 4000});

webSocketServer.on('request', function(request) {
  console.log("test!");

  const connection = request.accept(null, request.origin);
});   

I use npm to start the web server and there are no errors, warnings or crashes. When I use postman however to send a GET request it gives the code "426: Upgrade Required" But I'm guessing that's simply because I don't do anything yet with the connection. My main problem is the the console is not logging the "test!" when I send out this request. What am I doing wrong? Is there a better solution to this that I'm not seeing?

about 4 years ago · Juan Pablo Isaza
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