【发布时间】:2021-03-31 19:09:48
【问题描述】:
我正在尝试使用 Nodejs 将 2 个 API 放入一个页面。我已经搜索过相同的内容,但它说要使用 promise 包,但现在已弃用,请帮助我
app.post("/", function (req, res) {
const username = req.body.username;
const url1 = "https://codeforces.com/api/user.info?handles=" + username;
https.get(url1, function (response) {
response.on("data", function (data) {
const code = JSON.parse(data);
res.render("result", { id: username, rating: code.result[0].rating, rank: code.result[0].rank, freinds: code.result[0].friendOfCount, contri: code.result[0].contribution });
});
})
const url2 = "https://codeforces.com/api/user.status?handle=" + username;
https.get(url2, function (response) {
response.on("data", function (data) {
const code = JSON.parse(data);
res.render("result", { cid: code.result[0].contestId });
})
})
})
【问题讨论】:
-
哪个包被弃用了?