body-parser Flashcards
body-parser is
a parser of request bodies for Node.js, makes body available under req.body for the handlers
what are the types of data body-parser parses
x-www-form-urlencoded, text, raw, raw/json.
setting up body-parser
const bodyParser = require(‘body-parser’);
app. use(bodyParser.json([{config}]));
app. use(bodyParser.urlencoded());
extended=true in configuration allows
if set to true, you can post nested objects, ex:
{one: {two: ‘value’}}
it uses qs library if true, and uses querystring library if false
what is the difference between parsing incoming bodies as texts vs raw
raw suffers no modification, while text convers everything to strings.
raw() only looks are requests whose Content-type headers match the raw type. text() will only look the ones matching text format.