request-promise -我如何从函数外的Promise获得结果?

request-promise - How can I get the result from a Promise outside of the function?

本文关键字:Promise 结果 函数 request-promise      更新时间:2023-09-26

我使用request-promise,我有这段代码

func = (a) => {
  request(`http://somewebsite.com/${a}`).then((response) => response)
}

我想知道的是当我调用func(a)时如何得到响应?我是说,我如何从中获得响应对象?例如:

var b = func('path');
console.log(b) // Show me the response object, instead it shows undefined.

如何在承诺之外访问响应?

JavaScript没有类似于C#async/await。您需要访问回调函数内部的数据