简体   繁体   English

表示不推荐使用的 res.send(status, body):即使表达式更改,使用 res.status(status).send(body) 也不起作用

[英]express deprecated res.send(status, body): Use res.status(status).send(body) does not work even when expresion change

I'm trying to return a JSON on my POST for my Express App.我正在尝试在我的 POST 中为我的 Express 应用返回一个 JSON。

I recived the error "express deprecated res.send(status, body): Use res.status(status).send(body)" but even when i change the line with the error it stills shows the same error.我收到了错误“express deprecated res.send(status, body): Use res.status(status).send(body)”但即使我更改了带有错误的行,它仍然显示相同的错误。

My package.json is:我的 package.json 是:

{
  "name": "Email",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "start": "node app.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@azure/cognitiveservices-face": "^4.2.0",
    "@azure/ms-rest-js": "^2.6.0",
    "axios": "^0.23.0",
    "express": "^4.17.1",
    "nodemailer": "^6.7.0"
  }
}

The names that i use for express:我用于快递的名称:

const express = require("express");
const bodyParser = require("body-parser");

const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

The code that i'm trying to get a successful responce is:我试图获得成功响应的代码是:

app.post("/analisis/faceid", (req, res) => {
  let img = req.body.img;

  axios({
    method: "post",
    url: endpoint_faceID,
    params: {
      detectionModel: "detection_03",
      returnFaceId: true,
    },
    data: {
      url: img,
    },
    headers: {
      "Ocp-Apim-Subscription-Key": Ocp_Apim_Subscription_Key,
    },
  })
    .then(function (response) {
      let response_data = {
          mgs: "OK",
        faceId: response.data[0].faceId
      };
      res.send(response_data); //HERE IS WHERE THE ERROR APPEARS 
    })
    .catch(function (error) {
      res.send("ERROR AT FACE ID : ", error);
    });
});

I have tried replace it with:我尝试将其替换为:

res.json(response_data)
res.jsonp(200, response_data)
res.status(200).send(response_data)
res.status(200).send(JSON.stringify(response_data))
res.status(200).json(response_data)
res.status(200).jsonp(response_data)

But i keep getting the same error.但我不断收到同样的错误。

PD: sorry for my English PD:对不起我的英语

Thanks for everyone.谢谢大家。

The problem was the 2 arguments that i tryed to pass on the catch问题是我试图传递捕获的 2 个参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 res.send(status,body):改用res.status(status).send(body) - res.send(status, body): Use res.status(status).send(body) instead NodeJS Express Api——在路由外部调用 res.send 有效但 res.status 无论如何都不起作用 - NodeJS Express Api -- calling res.send outside route works but res.status does not work no matter what node-express 错误:表示已弃用 res.send(status):请改用 res.sendStatus(status) - node-express error : express deprecated res.send(status): Use res.sendStatus(status) instead 节点/ Express-res.status()。send()仅发送状态,不发送对象 - Node/Express - res.status().send() only sends the status but does not send an object res.status(400) 使我的链接 res.send(“this message”) 不会出现在客户端 - res.status(400) makes my chained res.send(“this message”) not show up on client side 发送res.status(409).send('error')不起作用 - doesn't work send in res.status(409).send('error') Node.js res.json() 和 res.send(),不工作但仍能更改状态码 - Node.js res.json() and res.send(), not working but still able to change status code Node Express测试模拟res.status(状态).json(obj) - Node Express testing mock res.status(status).json(obj) 类型错误:res.status 不是 function - TypeError: res.status is not a function NodeJS res.status 不是一个函数 - NodeJS res.status is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM