What are express.json() and express.urlencoded()?

前端 未结 3 1447
情歌与酒
情歌与酒 2020-12-22 17:18

I cannot find any documentation on express.json() and express.urlencoded(). What do each of them do exactly?

3条回答
  •  春和景丽
    2020-12-22 17:49

    The json and urlencoded middleware are both part of bodyParser. This is what the README says:

    bodyParser([options])

    Returns middleware that parses both json and urlencoded. The options are passed to both middleware.

    bodyParser.json([options])

    Returns middleware that only parses json. The options are:

    • strict - only parse objects and arrays
    • limit <1mb> - maximum request body size
    • reviver - passed to JSON.parse()

    bodyParser.urlencoded([options])

    Returns middleware that only parses urlencoded with the qs module. The options are:

    • limit <1mb> - maximum request body size

提交回复
热议问题