node package manager
It’s your turn. Help us improve JavaScript. Take the 2017 JavaScript Ecosystem Survey »



OpenLDAP client bindings for Node.js. Requires libraries from installed.


Any and all patches and pull requests are certainly welcome.

Thanks to:

  • Petr Běhan
  • YANG Xudong
  • Victor Powell


Node >= 0.6

For < 0.6 compaibility, check out v0.4


To build, ensure the OpenLDAP client libraries are installed, and

npm install -g, version)

Opens a new connection to the LDAP server or servers. Does not make a connection attept (that is saved until the first command is issued).

Basically, this call will always succeeds, but may throw an error in the case of improper parameters. Will not return an error unless no memory is available.

Open Example

    var LDAPConnection = require("../LDAP").Connection;
    var LDAP = new LDAPConnection();
    if ("ldap:// ldap://", 3) < 0) {
       throw new Error("Unable to connect to server");

Connection.simpleBind([dn, password,] callback(msgid, err));

Authenticates to the server. When the response is ready, or the timeout occurs, will execute the callback with the error value set.

dn and password must be omited, when doing anonymous bind., scope, filter, attrs, function(msgid, err, data))

Searches LDAP within the given base for entries matching the given filter, and returns all attrs for matching entries. To get all available attrs, use "*".

Scopes are specified as one of the following integers:

  • Connection.BASE = 0;
  • Connection.ONELEVEL = 1;
  • Connection.SUBTREE = 2;
  • Connection.SUBORDINATE = 3;
  • Connection.DEFAULT = -1;

If a disconnect or other server error occurs, the backing library will attempt to reconnect automatically, and if this reconnection fails, will return -1.

See also "man 3 ldap" for details.

Connection.searchPaged(base, scope, filter, attrs, pageSize, function(msgid, err, data) [, cookie])

LDAP servers are usually limited in how many items they are willing to return - 1024 or 4096 are some typical values. For larger LDAP directories, you need to either partition your results with filter, or use paged search.

Note that it's only extension to the protocol, server doesn't have to support it. In such case, callback will be called with nonzero err (actually, it would be nice if someone could verify this, the server it was tested on had this feature).

Cookie parameter is only for internal use, leave it undefined in your calls.

Results are passed to callback function as they arrive in the same format as for simple search. Request for next page is sent only after the callback returns. After all data has arrived, callback is called once more, with data equal to null.

Search Example

    var LDAPConnection = require("../LDAP").Connection;
    var LDAP = new LDAPConnection();
    // Open a connection."ldap://");"o=company", LDAP.SUBTREE, "(uid=alice)", "*", function(msgid, error, data) {
        switch(error) {
        case -2:
        case -1:
             console.log("Server gone away");


  • Document Modify, Add and Rename
  • Testing against Microsoft Active Directory is welcomed, as I don't have a server to test against.