Answer the question
In order to leave comments, you need to log in
How to make a value in a function global node.js?
the res value is returned in the function, how can this value be used outside the function?
Answer the question
In order to leave comments, you need to log in
etozh callback - so will never work.
at you at first create will be caused, then console.log. but whether the callback between them will be called - this is written with a pitchfork on the water.
```
ttttt.create({...}), function (err, res) {
if (err) throw err;
console log(res);
return res;
});
```
Through async should work. You only need nodejs 7.7.4, it works for me on this version.
var output;
var genNum = async function () {
return new Promise((resolve, reject) => {
setTimeout(() => {
return resolve(Math.random())
}, 1000)
})
}
output = await gennum();
console.log(output);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question