Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在post API中发出的node express请求_Node.js_Rest_Express - Fatal编程技术网

Node.js 在post API中发出的node express请求

Node.js 在post API中发出的node express请求,node.js,rest,express,Node.js,Rest,Express,在我的node express应用程序中,我尝试采用MVC方法,因此我将一些逻辑移到了控制器上。我从请求调用中得到了预期的结果,但由于某些原因,我无法使用res.send()返回结果。最后,我希望将响应保存在数组access\u token中,并将其发送回调用为响应的API 从我的控制器: 非常感谢您的帮助 路线 在请求回调中有两个res对象。将内部回调参数更改为其他名称,例如request(options,(err,response)=>{…;res.status(200).send(resp

在我的node express应用程序中,我尝试采用MVC方法,因此我将一些逻辑移到了控制器上。我从请求调用中得到了预期的结果,但由于某些原因,我无法使用
res.send()
返回结果。最后,我希望将响应保存在数组
access\u token
中,并将其发送回调用为响应的API

从我的控制器: 非常感谢您的帮助

路线
在请求回调中有两个
res
对象。将内部回调参数更改为其他名称,例如
request(options,(err,response)=>{…;res.status(200).send(response.body);

谢谢,就是这样!我完全忽略了这一点。
const access_token = []
exports.auth = (req, res, next) => {
  request(options, (err, res) => {
    if (err) throw new Error(err);
    console.log(res.body);
    res.status(200).send(res.body)
  })
};
router.post('/auth', sonflexController.auth)