Answer the question
In order to leave comments, you need to log in
Again async/await, how to synchronously get the result of a query into a variable?
Please, help!
I can not overcome the asynchronous request to the nedb database.
How to get a list of entries into the res variable?
const Datastore = require('nedb-promises')
let datastore = Datastore.create('./database/test.db')
var res = (async () => {
await datastore
.find({})
.then(function(docs){
console.log(docs) // здесь возвращает списк
return docs
})
})()
console.log(res) // здесь вместо списка Promise { <pending> }
Answer the question
In order to leave comments, you need to log in
The last console.log will not wait for your async. Why should he do this?
But everything that is written inside async will wait for await.
Friend, you made a promise without a return. Put a return on an arrow function. Now the function does not return anything. But globally, the code section is so-so.
PS Inside then also does not have a return. Write return Promise.resolve(data) if you still need the console
In your example with python, the value is also displayed in async. Why does this not suit the node?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question