0

I Am using the MEAN stack to develop an application following some video tutorials in the video he use the body-parser node.js module in the server side I want to understand why : does it convert application/json HTTP requests to a JSON object? so node.js can use JSON format to work on the Request ?

C.O.
  • 2,281
  • 6
  • 28
  • 51
Marwen Amri
  • 183
  • 1
  • 8

1 Answers1

0

by pure express you have only request headers and body as set of strings

but you want to work with set of parameters and values for doing backend jobs

https://github.com/expressjs/body-parser

it's allow you to parse request body into Object with {param: 'value'} structure, and deal with arrays and other complex structures inside body data

the name of library pretty self-explaining -> Parsing body data You can do it by yourself from scratch, but then you write another body-parser

at the github docs you'll see all supported content-types

vmkcom
  • 1,630
  • 11
  • 17
  • thank you for your response. so basically it enable me to convert a HTTP request from a **string** to **JSON object** to enable me to acces later on to a different elements inn the HTTP request using JSON notations for example req.body access to the body. and without it I'll have to deal with a stringify HTTP request. . Am I right ? and please is there any tool that i can use to see the stringify version of the request ? (firebug and Chrome console doesn't display it) – Marwen Amri Sep 03 '15 at 18:29
  • You can use `Charles` on OS X and `Fiddler` on Windows, shows you raw http packets. To get raw body from node.js try to look this: http://stackoverflow.com/questions/18710225/node-js-get-raw-request-body-using-express – vmkcom Sep 04 '15 at 12:48