body-parser Flashcards

1
Q

body-parser is

A

a parser of request bodies for Node.js, makes body available under req.body for the handlers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what are the types of data body-parser parses

A

x-www-form-urlencoded, text, raw, raw/json.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

setting up body-parser

A

const bodyParser = require(‘body-parser’);

app. use(bodyParser.json([{config}]));
app. use(bodyParser.urlencoded());

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

extended=true in configuration allows

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is the difference between parsing incoming bodies as texts vs raw

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly