Answer the question
In order to leave comments, you need to log in
How to make a function that returns the value received from https.request?
Greetings.
Tell me, please, to a person who is used to synchronous code, how to return a value in JS?
There is an algorithm in which I go over the users and call a certain method on them:
async function checkAll() {
...
for (let i in users) {
if (users[i].check()) {
users[i].checked = true
await users[i].save()
}
}
...
}
Schema.methods.check = async function () {
const req = https.request(options, (res) => {
res.on('data', (d) => {
// Как тут сделать return для родительского метода?
});
});
req.on('error', (e) => {
console.error(e.message);
});
req.end();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question