Search code examples
javascriptnode.jsrestpostmanform-data

Get the form-data key-values from the request


On Postman, if there is a POST request and it is added in Body > raw a JSON file, one can access inside the code with req.params.thatProperty.

For example, we have this JSON in Body:

{
    "email": "email@test.com",
    "password": "secret"
}

in code:

app.post('/myUrl', (req, res) => {
   //here we can access the email by req.params.email
}

My question is, if the have in Body > form-data like in the following screenshot, how can we access the email on the request? There it's no req.params in this case.

enter image description here But because I'm uploading a file and I'm using Multer, I do have access to req.file. The problem is that in req.file is only information related to the image, nothing about the email.

the function starts like this:

app.post('/upload', upload.single('value'), (req, res, next) => {
    //how can I have access to the email from the request here?
}

Solution

  • Your form data should be in req.body