当前位置: 首页 > 知识库问答 >
问题:

身体解析器已弃用[重复]

巩衡
2023-03-14

我试图在我的代码中使用Bodyparser,但代码被编辑器本身剪切,并表示Bodyparser已被弃用。我尝试了一些我在网上找到的替代代码,但都不起作用。附件是我正在使用的代码的截图。密码

代码:

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");
});

共有1个答案

宰父衡
2023-03-14

你可以很容易地找到它,关于它有很多答案。就用express吧

app.use(express.json);

 类似资料:
  • 我正在阅读Node和Express的Web开发这本书,遇到了一个障碍。 我被指示将下面的内容放在我的应用程序文件中,但它看起来像是已被弃用,无法工作。如何实现相同的功能? 这是我当前的代码:

  • 我的RecyclerAdapter的onBindViewHolder中有一个视图项。既然setBackgroundColor已被弃用,我应该怎么做?

  • 我被告知扩展在当前版本的PHP中已不推荐使用,并将在某个时候删除。 我应该用什么来代替这个,怎么用? 例如:

  • 下面的示例将展示将HTML fragement String解析为Element对象作为html正文。 语法 (Syntax) Document document = Jsoup.parseBodyFragment(html); Element body = document.body(); 哪里 document - document对象表示HTML DOM。 Jsoup - 解析给定HTML

  • 我曾经使用< code>MediaStore保存图像。Images.Media.insertImage,但< code>insertImage方法现在已被否决。医生说: 此方法在 API 级别 29 中已弃用。应使用 MediaColumns#IS_PENDING 执行图像的插入,这样可以更丰富地控制生命周期。 我不太明白,因为<code>媒体列。IS_PENDING只是一个标志,我应该如何使用它