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

233
Vistas
Express.js fetch API with FormData object

I have the following bit of code on a view

var fd = new FormData();
  fd.append("hello", "world");
  fetch('/vision', {
    method: 'post',
    "content-type": "application/json; charset=utf-8",
    body: JSON.stringify({
      hello: "world"
    })
  })
  .then(data => {
    debugger;
  })

and the action to handle

visionRouter.post("/", (req, res) => {
  vision.detectText(imageUrl, (err, text) => {
    res.send(text);
  })
});

The route is getting hit, but req.body doesn't exist. How can you use fetch and FormData with express?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You need to use the body-parser node module. Install it like this

npm install body-parser

Then in your code do this

var bodyParser = require("body-parser");
visionRouter.use(bodyParser.json());

Now your req.body will be able to access the JSON data you are sending

about 4 years ago · Santiago Trujillo 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