S
S
Sergey2020-05-04 20:16:21
Node.js
Sergey, 2020-05-04 20:16:21

How to get formData in nodejs?

Hello.
The site sends a post with a formData object to the nodejs server. I look at the result in the console - an empty object. The problem is probably in the wrong parser parameters. I will give the code below, please advise.

const express = require ('express');
const bodyParser = require('body-parser');
const app = express();
const cors = require('cors');
const PORT = 3000;
const parser = bodyParser.urlencoded({extended:false});


app.use(cors())

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

app.listen(PORT, (err)=>{
    console.log(`Server starting on ${PORT} port`)
})

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
McBernar, 2020-05-04
@McBernar

The answer to the question is Googled in a second.
here

M
microlabig, 2020-05-04
@microlabig

Nice and simple package for solving the formidable problem https://www.npmjs.com/package/formidable

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question