Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's bodyParser() and CookieParser

wht's the role of app.use(bodyParser.json()); app.use(bodyParser.urlencoded());

and what's the difference between bodyParser() and CookieParser()

like image 586
hunter-x Avatar asked Feb 20 '26 07:02

hunter-x


2 Answers

body-parser is a body parsing middleware, which populates the req.body with (for example) the value of the parametres of a POST.

cookie-parser parses cookies and populates req.cookies with objects bidden to cookie names.

like image 173
Cihan Bebek Avatar answered Feb 22 '26 02:02

Cihan Bebek


bodyParser.json() - a middleware used for going over POST request data, parse it into json on put it on req.body.

cookieParser() - a middleware that parse cookie header and populate req.cookies

like image 21
Ben Diamant Avatar answered Feb 22 '26 00:02

Ben Diamant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!