Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
Can't send data through axios and node back-end

I am trying to access the expression passed from the backend to the frontend through axios.

Producer side:

const axios = require('axios');
const URL = "http://localhost:5000/"
let n1 = 3
let n2 = 5
let sum = n1+n2;



axios.post(URL, JSON.stringify({
    expression: sum,
  }))
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

and on the consumer side:

const express = require('express')
const app = express()

app.post('/', (req, res) => {
  console.log(req.body);
})

app.listen(5000, () => console.log())

Ultimately, I would like to have the consumer side log "8"

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

From the "express" documentation:

req.body

Contains key-value pairs of data submitted in the request body. By default, it is undefined, and is populated when you use body-parsing middleware such as body-parser and multer.

Try including this before you try to register the endpoint:

const bodyParser = require('body-parser')

app.use(bodyParser.json())

You can also use express.json() and drop the 'body-parser' dependency:

// const bodyParser = require('body-parser')

app.use(express.json())
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda