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

237
Visualizações
How to send axios post to socket io server?

I need to send a POST to a socket.io server and print it on the screen. This needs to be done in real time. I will open up socket io server, leave it open on my browser, and every time I send a post to it, it needs to print the value on the screen. I have no prior experience in Node,so I'm a little bit lost on how to do it. This is my socket.io server (almost the exact same one from the documentation tutorial):

const express = require('express');
const app = express();
const http = require('http');
const server = http.createServer(app);
const { Server } = require("socket.io");
const io = new Server(server);

    app.get('/', (req, res) => {
      res.sendFile(__dirname + '/index.html');
    });
    
    io.on('connection', (socket) => {
      console.log("USER CONNECTED!")
      
    });
    server.listen(3000, () => {
      console.log('listening on *:3000');
    });

And I'm sending a post to it from another server every time it gets a request. I'm using axios:

axios.post('http://myhost:3000/',qs.stringify({
     test: 'test'
   }))
   .then(res => {
     console.log(` >STATUS: ${res.status}`);
    })
   .catch(error => {
     console.error(error);
   })

This is the error I'm getting:

Error: Request failed with status code 404
at createError (/var/www/html/MYFOLDER/node_modules/axios/lib/core/createError.js:16:15)
at settle (/var/www/html/MYFOLDER/node_modules/axios/lib/core/settle.js:17:12)
at IncomingMessage.handleStreamEnd (/var/www/html/ROMA/node_modules/axios/lib/adapters/http.js:269:11)
at IncomingMessage.emit (node:events:402:35)
at endReadableNT (node:internal/streams/readable:1340:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)

I don't know exactly how to do what I described. Any other suggestion is accepted,not only fixes on my code.

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