zoukankan      html  css  js  c++  java
  • “bodyParser”已被弃用, bodyParser is deprecated.


    源码为:

    const express = require('express');
    const expressHandlebars = require('express-handlebars');
    const path = require('path');
    const bodyParser = require('body-parser')
    
    const app = express();
    const port = process.env.PORT || 3000;
    
    // 使用body-parser中间件解析请求主体
    app.use(bodyParser.urlencoded({ extended: false }))
    

    问题

    在vscode中使用body-parser中间件,显示bodyParser已被弃用,bodyParser is deprecated.

    原因以及解决

    Express4.16+已经加入了bodyParser,不需要再require,可直接作为express的方法使用.

    body-parser正确使用:

    const express = require('express');
    const expressHandlebars = require('express-handlebars');
    const path = require('path');
    
    const app = express();
    const port = process.env.PORT || 3000;
    
    // 使用body-parser中间件解析请求主体
    app.use(express.urlencoded({ extended: false }))
    
    本文采用知识共享署名 4.0 国际许可协议进行许可。 转载时请注明原文链接,如果对本文 的内容有疑问,请留言,谢谢。
  • 相关阅读:
    友元类和友元函数
    C++中构造函数和析构函数调用的时机
    Linux 下svn恢复到某一版本
    lua 中pairs 和 ipairs区别
    孤儿进程与僵尸进程
    union
    关于C++ const 的全面总结
    后台管理左侧菜单
    全选-反选-取消
    Dom-直接 /间接选择器
  • 原文地址:https://www.cnblogs.com/wljqds/p/14953472.html
Copyright © 2011-2022 走看看