Using Bluebird Promises, an easy way to do this is to create a client normally and then run promisifyAll () on the client.
var ldap = require('ldapjs'); var Promise = require('bluebird'); var client = ldap.createClient({ url: 'ldap://my-server:1234', }); Promise.promisifyAll(client);
Now you can call client.addAsync () and client.searchAsync (), etc.
client.bindAsync(secUserDn, secUserPassword) .then(doSearch) // if it works, call doSearch .catch(function (err) { // if bind fails, handle it console.error('Error on bind', err) }); function doSearch(data) { client.searchAsync('CN=A Test,OU=Users,DC=website,DC=com', options) .then(function (data) { // Handle the search result processing console.log('I got a result'); }) .catch(function (err) { // Catch potential errors and handle them console.error('Error on search', err); }); }
source share