What does 'extended' mean in express 4.0?
I'm using express and also body-parser in my app.
app.use(bodyParser.urlencoded({ extended: false }));
But, What does 'extended' mean in express 4.0?
I found this
extended - parse extended syntax with the qs module.
However, I still can't understrand what it means.
If extended
is false
, you can not post "nested object"
person[name] = 'cw'
// Nested Object = { person: { name: cw } }
If extended
is true
, you can do whatever way that you like.
When
extended
property is set totrue
, the URL-encoded data will be parsed with the qs library.
On the contrary,
when
extended
property is set tofalse
, the URL-encoded data will instead be parsed with the querystring library.
The differences between parsing with `qs library` vs `querystring library`
qs library allows you to create a nested object from your query string.
var qs = require("qs") var result = qs.parse("person[name]=bobby&person[age]=3") console.log(result) // { person: { name: 'bobby', age: '3' } }
query-string library does not support creating a nested object from your query string.
var queryString = require("query-string") var result = queryString.parse("person[name]=bobby&person[age]=3") console.log(result) // { 'person[age]': '3', 'person[name]': 'bobby' }
qs library will not filter out '?' from the query string.
var qs = require("qs") var result = qs.parse("?a=b") console.log(result) // { '?a': 'b' }
query-string library will filter out '?' from the query string.
var queryString = require("query-string") var result = queryString.parse("?a=b") console.log(result) // { a: 'b' }
app.use(bodyParser.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded
For more information, you may refer to Leonid Beschastny's answer, and npm compare qs vs query-string.
From the Body-Parser docs:
A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body). This object will contain key-value pairs, where the value can be a string or array (when extended is false), or any type (when extended is true).
And
The extended option allows to choose between parsing the URL-encoded data with the querystring library (when false) or the qs library (when true). The "extended" syntax allows for rich objects and arrays to be encoded into the URL-encoded format, allowing for a JSON-like experience with URL-encoded. For more information, please see the qs library.
Basically extended allows you to parse full objects.
참고URL : https://stackoverflow.com/questions/29960764/what-does-extended-mean-in-express-4-0
'Nice programing' 카테고리의 다른 글
Pass data through segue (0) | 2020.11.16 |
---|---|
BREW 오류 : 심볼릭 링크 불가, 경로 쓰기 불가 (0) | 2020.11.16 |
iPhone없이 Apple 푸시 알림 서비스를 테스트하려면 어떻게해야합니까? (0) | 2020.11.16 |
HashMap : 하나의 키, 여러 값 (0) | 2020.11.16 |
Collections.synchronizedList 및 동기화 됨 (0) | 2020.11.16 |