When i create new variable and assign callback function, But data cannot return from callback function. Undefined is occurring at new variable.
const nedb = require('nedb');
const user = new nedb({ filename: './builds/database/users.db', autoload: true });
var s = user.find({}, function (err,docs) {
if(docs.length == 0) {
var data = false;
} else {
var data = docs;
}
return data;
});
console.log(s);
var s is undefined! ....
console.log(s);will execute immediately after assigning function tovar s, and function returns the value after the find query, so the inital value will beundefined, you need to wait till it return to print the value. you can't just assign it like above..