express Flashcards
why do you need body parser
in express, req implemented the ReadableStream
body-parser extracts the entire body portion of an incoming request stream and exposes it on req.body.
the body data is the stream content.
you need to to conver the stream content into Javascript object in req.
if it’s written in JSON, you need parse it with JSON.parse
if it’s URL-encoded, you will use some other approach to do the parsing.
JSON body parser
Raw body parser
Text body parser
URL-encoded form body parser
https://stackoverflow.com/questions/38306569/what-does-body-parser-do-with-express#:~:text=In%20order%20to%20get%20access,object%20that%20we%20can%20understand.
form data multipart content?
–«boundary_value»
Content-Disposition: form-data; name=”«field_name»”
«field_value»