I came across lots of blogs and article they have suggested to use body-parser to parse request body data . Is there any way to parse-data or get body data from body without using any middle-ware?
By default, express just gives you the raw HTTP request body in the req
argument as a IncomingMessage
which is basically a Readable
stream. When you, e.g., make a form POST request, the form might be encoded in various ways if made by a web browser or it might be JSON or some arbitrary format. The body-parser
module knows how to read the HTTP request body and understands a particular list of various common encodings.
Express is mostly just a very simple framework for hooking middleware together and declaring routing for your application. By doing very little and doing very well at it, it is unopinionated and usable by more people. For example, if you wanted to send your own format in an HTTP request, you might need to write your own code instead of using body-parser
. Some HTTP server frameworks have a baked-in equivalent. In such frameworks, it might be hard/confusing to extend the body parsing functionality or even impossible. The Express project suggests body-parser
, but if there’s a different module which parses the body in a way you like better, you can always use that instead.