节点JS请求多个URL同时
问题描述:
我想请求与新公共管理的要求库中的多个网址,并在JSON返回结果节点JS请求多个URL同时
我的代码是,但不工作。
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
},
答
您可以使用类似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
});
又该它返回? – niceman
并不重要,它不工作 – user8026867
它应该返回什么? :3(它确实很重要:)) – niceman