Tengo el siguiente bit de código en una vista
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; })y la acción a manejar
visionRouter.post("/", (req, res) => { vision.detectText(imageUrl, (err, text) => { res.send(text); }) }); La ruta está siendo atacada, pero req.body no existe. ¿Cómo puedes usar fetch y FormData con express?
Debe utilizar el módulo de nodo body-parser . Instálalo así
npm install body-parserLuego en tu código haz esto
var bodyParser = require("body-parser"); visionRouter.use(bodyParser.json()); Ahora su req.body podrá acceder a los datos JSON que está enviando