Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Req.body is empty while using Post Request

App.js

app.use(express.json({limit:"30mb",extended:true}));
app.use(express.urlencoded({extended:true}));

route.js
router.route("/register").post(registerUser)

importing Routes in app.js

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import userRoute from './routes/user.route.js';

app.use("/users",userRoute);```


const {fullName,email,username,password} = req.body;
console.log("req.body: ",req.body);

output:
req.body:  {}
Error: All input is required








I'm trying to register user with files but req.body is empty if I'm trying to use normal form in postman but if I'm trying x-www-form-urlencoded it works but cann't upload file there

>Solution :

In route.js File

router.post("/register", (req, res) => {
    const {fullName, email, username, password} = req.body; 
    console.log("req.body: ",req.body);
});

Using this code.
I think it resolve your problem.

If nothing happened, please check sending message in Network of the Browser.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading