Sometimes, we want to handle FormData with Node.js Express.js 4.
In this article, we’ll look at how to handle FormData with Node.js Express.js 4.
How to handle FormData with Node.js Express.js 4?
To handle FormData with Node.js Express.js 4, we can use multer.
To install it, we run
npm i multer
Then we use it by writing
const multer = require("multer");
const upload = multer();
app.post("/send", upload.none(), (req, res) => {
const formData = req.body;
console.log("form data", formData);
res.sendStatus(200);
});
to call multer to return the upload object.
Then we use the upload.none method to return a middleware that doesn’t take file uploads but parses form data requests.
Next, we get the form data requests from req.body in the route handler.
Conclusion
To handle FormData with Node.js Express.js 4, we can use multer.