Javascript 节点js同时请求多个URL

Javascript 节点js同时请求多个URL,javascript,node.js,npm,Javascript,Node.js,Npm,我想使用npm的请求库请求多个URL,并在json上返回结果 我的代码就是这样,但不起作用 request({ url: "https://www.googleapis.com/youtube/v3/commentThreads?part=snippet&videoId="+item+"&key=AIzaSyCPv-dasd&maxResults=100&", url: "https://www.googleapis.com/youtube/v3/c

我想使用npm的请求库请求多个URL,并在json上返回结果

我的代码就是这样,但不起作用

request({
    url: "https://www.googleapis.com/youtube/v3/commentThreads?part=snippet&videoId="+item+"&key=AIzaSyCPv-dasd&maxResults=100&",
   url: "https://www.googleapis.com/youtube/v3/commentThreads?part=snippet&videoId="+item+"&key=AIzaSyCPv-dasd&maxResults=100&",
    json: true
}, 

如果您提到的请求库是,那么它只允许每个请求有一个URL,因此您需要对每个URL进行单独调用


希望它能有所帮助。

为了使用承诺,你可以使用类似“蓝鸟promisify”的东西:

const bluebird = require('bluebird');
const promiseRequest = bluebird.promisify(require('request'));

Promise.all([
  promiseRequest(//request1 here),
  promiseRequest(//request2 here),
])
.then(function(res1, res2) {
  //Deal with results here
})
.catch(function(error) {
  //Deal with error
});

它应该返回什么?不管它不工作,它应该返回什么3(这很重要:))来自youtube的json响应。。。。这有关系吗?json响应,因为此请求url:url:style不起作用例如,如果第一个url返回json
{prop1:“你好”,prop2:2}
,第二个url返回
{prop1:“你好”,prop2:1,prop3:[2,3]}
{prop1:“你好”,prop2:3,prop3:[2,3]}或
{prop1:“你好”,prop2:2,prop3:[2,3]}
或。。。