Ok figured it out. it should be in the on end.
res.on('end', function(result) {
console.log('status: ' + result.status);
response.send(entries)
});
On Sunday, January 14, 2018 at 6:43:54 AM UTC-8, Arnaud Deman wrote:
>
>
> Hi Tito,
>
> I will compare with my code tomorow when I am in the office, but I wonder
> if it is not an async problem.
> As you say r has data in it, it could be that entries is returned before
> being populated ?
>
> Regards,
> Arnaud.
>
>
> Le samedi 13 janvier 2018 02:15:36 UTC+1, Tito a écrit :
>>
>> Given the following code in my index.js, I want to be able to return the
>> array entries. But it comes back [] what may I be doing wrong? entry.object
>> is fully populated hence r does have data in it.
>>
>> Thanks!
>>
>> function getDistributinGroups(req, res, next) {
>> var sAMAccountName = res.locals.ntlm.UserName;
>> var groups = 'OU=Fee,OU=Figh,DC=Fo,DC=lan';
>>
>> const client = ldapjs.createClient(ldapOptions);
>>
>> var opts = {
>> scope: 'sub',
>> filter: '&(mail=*@*)(managedBy=*)',
>> attributes: ['dn', 'sn', 'cn','managedBy','mail']
>> };
>>
>> client.bind(
>> ldapconfig.username,
>> ldapconfig.password, function(err) {
>> assert.ifError(err);
>> });
>>
>> let entries = [];
>>
>> client.search(groups, opts, function(err, res) {
>> assert.ifError(err);
>>
>> res.on('searchEntry', function(entry) {
>> var r = entry.object;
>> entries.push(r);
>> });
>> res.on('searchReference', function(referral) {
>> console.log('referral: ' + referral.uris.join());
>> });
>> res.on('error', function(err) {
>> console.error('error: ' + err.message);
>> });
>> res.on('end', function(result) {
>> console.log('status: ' + result.status);
>> });
>> });
>>
>> console.log(entries);
>>
>> res.send(entries)
>>
>> }
>>
>
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.