0

Hi I am trying to run a post request using connect-busboy but not able to do so. additionally I am not able to pinpoint the error as it is not showing any error.

Additionally I am using postman to check the router with the below settings : x-www-form-urlencoded

If someone can please help me resolve this issue.

Please let me know if you require any further information from my end.

Please find below the necessary code :

user profile.js

router.post('/userprofile/check/busboy', async (req,res) => {
  console.log(req.body);
 // const busboy = Busboy({headers: req.headers});
  
  const fields = {};
  req.busboy.on('field', (fieldname, val) => {
    console.log('reached till here');
    if(fieldname === 'userId') {
      console.log(`Processed field ${fieldname}: ${val}.`);
    }
    
    fields.set(fieldname,val)
    fields[fieldname] = val;
  });

  req.busboy.on('finish', function() {
    console.log('Done parsing form!');
    
  });

app.js

var busboy = require('connect-busboy');

app.use(busboy());
akm
  • 149
  • 1
  • 9

1 Answers1

0

You are not sending a response back to your client

  req.busboy.on('field', function() {
    // finished processing your request
    res.status(200).send();
  });

Not familiar with busboy and their documentation looks lacking. I can't see any reference to a finish event handler in their documentation.

jeeves
  • 1,871
  • 9
  • 25
  • 1
    Hi Jeeves thanks for your response..I was manage to resolve the issue...the solution was to put res.pipe(req.busboy) at the end – akm Oct 18 '22 at 13:09