Sometimes, we want to fix the ‘BodyParser is deprecated’ warning with Node.js and Express.
In this article, we’ll look at how to fix the ‘BodyParser is deprecated’ warning with Node.js and Express.
How to fix the ‘BodyParser is deprecated’ warning with Node.js and Express?
To fix the ‘BodyParser is deprecated’ warning with Node.js and Express, we can replace bodyParser
with express.urlencoded
and express.json
.
For instance, we write
app.use(express.urlencoded({
extended: true
}));
app.use(express.json())
to call app.use
with the middlewares returned by express.urlencoded
and express.json
to let us parse URL encoded and JSON request bodies.
Conclusion
To fix the ‘BodyParser is deprecated’ warning with Node.js and Express, we can replace bodyParser
with express.urlencoded
and express.json
.