我试图在我的代码中使用 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("/",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");
});