express throws error as `body-parser deprecated undefined extended`

后端 未结 6 2082
囚心锁ツ
囚心锁ツ 2020-12-23 08:29

In my node app, I am using express. all works fine, But i am getting error in the cmd. I use all are updated modules...

my code :

相关标签:
6条回答
  • 2020-12-23 09:10

    If you are here, after May-2020 that means you are surely using node of version v13.12.0.. So, app.use(express.urlencoded({ extended: true }))

    This Surely Gonna works for You....#peace

    0 讨论(0)
  • 2020-12-23 09:17

    Set limit 50 MB for avoid data handling error., In urlencode limit 50mb is for help you to pass imageData throw url

      app.use(bodyParser.json({
            limit : '50mb'    ///////// LIMIT for JSON
          }));
    
        app.use(bodyParser.urlencoded({
            limit : '50mb', ///////// LIMIT for URL ENCODE (image data)
            extended : true
          }));
    
    0 讨论(0)
  • 2020-12-23 09:21

    Attention: With express version => 4.16.0 the body-parser middleware was added back under the methods express.urlencoded() and express.json()

    Which can be used as:

    app.use(express.urlencoded({extended: true})); 
    app.use(express.json());   
    
    0 讨论(0)
  • 2020-12-23 09:21

    The error says you need to provide the extended option for the body-parser like so:

    app.use(bodyParser.urlencoded({ extended: false }))
    
    0 讨论(0)
  • 2020-12-23 09:31

    You have to explicitly set extended for bodyParser.urlencoded() since the default value is going to change in the next major version of body-parser. Example:

    app.use(bodyParser.urlencoded({ extended: true }));
    

    Since express 4.16.0, you can also do:

    app.use(express.urlencoded({ extended: true }))
    
    0 讨论(0)
  • 2020-12-23 09:32

    As from Express version 4.16.0, you're expected to pass in extended property inside the bodyParser.urlencoded()

    //  parse JSON-encoded bodies and URL-encoded bodies
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: false }));
    

    See npm.js documentation page for sample: https://www.npmjs.com/package/body-parser#expressconnect-top-level-generic

    0 讨论(0)
提交回复
热议问题