{"id":27919,"library":"ldap","title":"ldapjs","description":"LDAPjs is a pure JavaScript implementation of the LDAP protocol for Node.js, providing both client and server APIs. The current stable version is 3.0.7, released with bug fixes and security improvements. Version 3.0.0 introduced a major overhaul, splitting core LDAP operations into separate packages like @ldapjs/messages and @ldapjs/controls, and dropping support for older Node.js versions (<14). It is actively maintained, with regular releases and a focus on standards compliance and extensibility. Compared to alternatives like ldap-client or passport-ldapauth, ldapjs offers a lower-level, more flexible API suitable for building custom LDAP servers and clients.","status":"active","version":"0.7.1","language":"javascript","source_language":"en","source_url":"git://github.com/mcavage/node-ldapjs","tags":["javascript"],"install":[{"cmd":"npm install ldap","lang":"bash","label":"npm"},{"cmd":"yarn add ldap","lang":"bash","label":"yarn"},{"cmd":"pnpm add ldap","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency for LDAP message encoding/decoding (v3+)","package":"@ldapjs/messages","optional":false},{"reason":"Core dependency for LDAP control support (v3+)","package":"@ldapjs/controls","optional":false}],"imports":[{"note":"ldapjs is a CommonJS module and does not support ESM default import. Use require() instead.","wrong":"import ldap from 'ldapjs';","symbol":"default (ldap)","correct":"const ldap = require('ldapjs');"},{"note":"Named exports are available via destructuring, but ensure the module is required first. Direct destructuring without require is not valid.","wrong":"const { createClient } = require('ldapjs'); const client = createClient({ url: '...' });","symbol":"createClient","correct":"const ldap = require('ldapjs'); const client = ldap.createClient({ url: 'ldap://localhost:1389' });"},{"note":"Same as above: require the module, then destructure.","wrong":"const { Attribute } = require('ldapjs'); const attr = new Attribute({ ... });","symbol":"Attribute","correct":"const ldap = require('ldapjs'); const attr = new ldap.Attribute({ type: 'cn', vals: ['test'] });"}],"quickstart":{"code":"const ldap = require('ldapjs');\n\n// Create a server\nconst server = ldap.createServer();\n\nserver.search('dc=example', (req, res, next) => {\n  const obj = {\n    dn: req.dn.toString(),\n    attributes: {\n      objectclass: ['organization', 'top'],\n      o: 'example'\n    }\n  };\n  if (req.filter.matches(obj.attributes)) res.send(obj);\n  res.end();\n});\n\nserver.listen(1389, () => {\n  console.log('LDAP server listening at ' + server.url);\n});\n\n// Also create a client\nconst client = ldap.createClient({ url: 'ldap://localhost:1389' });\nclient.bind('cn=root', 'secret', (err) => {\n  if (err) console.error(err);\n  else console.log('bound');\n});\nclient.unbind();","lang":"javascript","description":"Creates a simple LDAP server that responds to searches, and a client that binds and unbinds."},"warnings":[{"fix":"Upgrade Node.js to v14 or later.","message":"Version 3.0.0 dropped support for Node.js versions <14. Upgrade Node if using older versions.","severity":"breaking","affected_versions":"<3.0.0"},{"fix":"Install @ldapjs/messages and @ldapjs/controls as dependencies and import from those packages.","message":"In v3.0.0, LDAP messages and controls are now separate packages (@ldapjs/messages, @ldapjs/controls). Code that directly uses internal message types may break.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Set ldap.Attribute.settings.guid_format = ldap.GUID_FORMAT_D before accessing objectGUID.","message":"The default GUID format changed in v2.x; you must set ldap.Attribute.settings.guid_format to enable formatting, otherwise it returns raw buffer.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Update to v3.x: npm install ldapjs@latest","message":"The v2.x branch is no longer receiving updates. Users should migrate to v3.x.","severity":"deprecated","affected_versions":"<3.0.0"},{"fix":"Use event listeners: client.search() returns a Search object with 'searchEntry' and 'end' events.","message":"Client search results are now Stream2 (v2+) and require listening to 'searchEntry' events; the old callback style with result.object is deprecated and may be removed.","severity":"gotcha","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Run 'npm install ldapjs' in your project directory.","cause":"ldapjs is not installed or not in node_modules.","error":"Cannot find module 'ldapjs'"},{"fix":"Upgrade to a newer version: 'npm install ldapjs@latest'","cause":"Attribute.settings was added in v2.0.0; if you are on v1.x it does not exist.","error":"ldap.Attribute.settings is undefined"},{"fix":"Check your server setup: ldap.createServer() returns a server object with .search(), .bind(), etc.","cause":"server.search is a method but may be misspelled; it expects a string DN and a handler.","error":"TypeError: server.search is not a function"},{"fix":"Use a valid DN string; escape special characters if needed.","cause":"LDAP DNs must be properly formatted (e.g., 'dc=example,dc=com').","error":"Error: Invalid DN"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}