我正在学习Node.JS,并向我介绍了请求承诺包。我将其用于API调用,但是遇到了无法对其应用循环的问题。
这是显示一个简单的API调用的示例:
var read_match_id = {
uri: 'https://api.steampowered.com/IDOTA2Match_570/GetMatchHistory/V001',
qs: {
match_id: "123",
key: 'XXXXXXXX'
},
json: true
};
rp(read_match_id)
.then(function (htmlString) {
// Process html...
})
.catch(function (err) {
// Crawling failed...
});
Run Code Online (Sandbox Code Playgroud)
我怎么有这样的循环:
var match_details[];
for (i = 0; i < 5; i++) {
var read_match_details = {
uri: 'https://api.steampowered.com/IDOTA2Match_570/GetMatchDetails/V001',
qs: {
key: 'XXXXXXXXX',
match_id: match_id[i]
},
json: true // Automatically parses the JSON string in the response
};
rp(read_match_details)
.then (function(read_match){
match_details.push(read_match)//push every result to the array
}).catch(function(err) …Run Code Online (Sandbox Code Playgroud) 最近,我正在学习Node.js作为后端语言。我发现人们通常使用MEAN来做,我的问题是是否需要一个前端框架来使用Node.JS?
对于诸如angular和react这样的前端框架,哪一个更适合Node.js?
我进行了一些研究,但是我看到大多数人在Nodejs的MEAN中使用angular作为A。我能知道为什么吗?