【发布时间】:2021-10-04 16:37:41
【问题描述】:
我试图在我的代码中使用 Bodyparser,但代码被编辑器本身剪切并说 body-parser 已被弃用。我尝试了一些在网上找到的替代代码,但没有一个有效。 附上我正在使用的代码截图。Code
代码:
const express = require("express");
const bodyParser = require("body-parser");
const app = express()
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.get("/", function(req, res){
res.sendFile(__dirname + "/index.html");
});
app.post("/", function(req, res){
var num1 = req.body.num1;
var num2 = req.body.num2;
var result = num1 + num2;
res.send("The result of the calculation is " + result);
});
app.listen(3000, function(){
console.log("Server has started on port3000");
});
【问题讨论】:
-
express 有自己的正文解析器 - 阅读文档 - 或 this
-
这能回答你的问题吗? bodyParser is deprecated express 4
标签: javascript node.js express node-modules body-parser