{"id":15676,"library":"ldapjs-client","title":"LDAP.js Client","description":"ldapjs-client is a JavaScript LDAP client library designed for modern Node.js environments, requiring Node.js >= 8.0. It offers a promise-based API for asynchronous interactions with LDAP servers, supporting common operations such as adding, binding, deleting, modifying, renaming (modifyDN), and searching for entries. A primary distinguishing feature of `ldapjs-client` is its intentional independence from the `ldapjs` package, which has been unmaintained for several years. This package positions itself as an actively supported alternative, addressing the need for robust LDAP client functionality in contemporary Node.js applications. The current stable version is 0.1.7. While specific release cadences are not detailed, the presence of continuous integration workflows suggests ongoing development and maintenance.","status":"active","version":"0.1.7","language":"javascript","source_language":"en","source_url":"git://github.com/zont/ldapjs-client","tags":["javascript","LDAP","ldap","client","simple","promised","async"],"install":[{"cmd":"npm install ldapjs-client","lang":"bash","label":"npm"},{"cmd":"yarn add ldapjs-client","lang":"bash","label":"yarn"},{"cmd":"pnpm add ldapjs-client","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library primarily exports a default class for ESM. Named import is incorrect.","wrong":"import { LdapClient } from 'ldapjs-client';","symbol":"LdapClient","correct":"import LdapClient from 'ldapjs-client';"},{"note":"CommonJS import for Node.js environments.","symbol":"LdapClient","correct":"const LdapClient = require('ldapjs-client');"},{"note":"All operations are promise-based; direct callbacks are not supported.","wrong":"client.add('cn=foo, o=example', entry, (err, res) => {});","symbol":"client.add","correct":"await client.add('cn=foo, o=example', entry);"}],"quickstart":{"code":"import LdapClient from 'ldapjs-client';\n\nconst client = new LdapClient({\n  url: 'ldap://127.0.0.1:389',\n  timeout: 5000 // 5-second timeout for operations\n});\n\nasync function performLdapSearch() {\n  try {\n    // Assuming an anonymous bind is allowed for search, or bind first\n    // await client.bind('admin_user', process.env.LDAP_PASSWORD ?? '');\n\n    const options = {\n      filter: '(&(objectclass=person)(cn=*))', // Search for any person entry\n      scope: 'sub',\n      attributes: ['dn', 'cn', 'mail']\n    };\n    console.log('Searching LDAP...');\n    const entries = await client.search('o=example', options);\n    console.log(`Found ${entries.length} entries:`)\n    entries.forEach(entry => console.log(entry.dn, entry.cn, entry.mail));\n\n    // Clean up connection\n    await client.unbind();\n    await client.destroy();\n  } catch (e) {\n    console.error('LDAP operation failed:', e.message);\n    // Ensure client is destroyed even on error\n    if (client) await client.destroy().catch(err => console.error('Error destroying client:', err.message));\n  }\n}\n\nperformLdapSearch();","lang":"typescript","description":"This quickstart demonstrates how to create an LDAP client, perform a basic search operation, and properly close the connection using asynchronous promise-based syntax."},"warnings":[{"fix":"Use `npm install ldapjs-client` instead of `npm install ldapjs`.","message":"This package (`ldapjs-client`) is distinct from the original `ldapjs` package. The original `ldapjs` is largely unmaintained and has known issues. Always ensure you are installing `ldapjs-client` when seeking an actively maintained LDAP client.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Always use `await` with client operations or handle the returned Promise with `.then()` and `.catch()`.","message":"All client operations return Promises. Mixing with traditional callback patterns from older LDAP libraries will lead to unexpected behavior and unhandled promise rejections.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Pass only `proto://host:port` to the `url` option. Other search parameters like `filter`, `scope`, `attributes` should be passed as separate options to the `search` method.","message":"The `url` option for `LdapClient` constructor must be a valid LDAP URL containing only the protocol, host, and port (e.g., 'ldap://localhost:389' or 'ldaps://myldap.com:636'). It does not support additional path components or query parameters in the URL string itself.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Verify the LDAP server is running and reachable from the client's network. Check the IP address and port in the `url` option of the LdapClient constructor for correctness.","cause":"The LDAP server specified in the client URL is not running or is not accessible on the specified host and port.","error":"Error: connect ECONNREFUSED 127.0.0.1:389"},{"fix":"Double-check the credentials used in `client.bind('username', 'password')`. Ensure the DN is correctly formatted and the password matches the LDAP server's record.","cause":"The username (DN) or password provided during the `bind` operation is incorrect or does not have sufficient permissions.","error":"Error: LDAP_INVALID_CREDENTIALS"},{"fix":"Verify the exact DN string for the target entry. Use an LDAP browser or `search` operation to confirm the existence and correct DN of the object before performing modifications or deletions.","cause":"The Distinguished Name (DN) provided for operations like `add`, `del`, `modify`, or `modifyDN` does not exist on the LDAP server.","error":"Error: LDAP_NO_SUCH_OBJECT"}],"ecosystem":"npm"}