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
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
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.
forgot to use multer middleware in route now it is working
router.route("/register").post(upload.single("profilePic"),registerUser);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With