I am using ldapjs library in nodejs. I want to access the results of client.search outside of the function. Here is my code
items = [];
client.search('cn=users,dc=test,dc=com', opts, function (err, res) {
if (err)
console.log(err);
res.on('searchEntry', function (entry) {
items.push(entry.object);
});
res.on('error', function (err) {
console.error('error: ' + err.message);
});
res.on('end', function (result) {
console.log('status: ' + result.status);
console.log(items[0]); **//Prints results correctly**
});
});
console.log(items[0]); **//Prints []**
I tried return items inside search. Still doesn't print. Any suggestions?