Registry / auth-security / ldap
library0.7.1jsnpmunverified

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.

npm install ldap
INSTALL
IMPORT
SIG · LDAP
L
ldap
auth-securityjavascriptv0.7.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (ldap)
const ldap = require('ldapjs');
import ldap from 'ldapjs';
ldapjs is a CommonJS module and does not support ESM default import. Use require() instead.
createClient
const ldap = require('ldapjs'); const client = ldap.createClient({ url: 'ldap://localhost:1389' });
const { createClient } = require('ldapjs'); const client = createClient({ url: '...' });
Named exports are available via destructuring, but ensure the module is required first. Direct destructuring without require is not valid.
Attribute
const ldap = require('ldapjs'); const attr = new ldap.Attribute({ type: 'cn', vals: ['test'] });
const { Attribute } = require('ldapjs'); const attr = new Attribute({ ... });
Same as above: require the module, then destructure.

Creates a simple LDAP server that responds to searches, and a client that binds and unbinds.

const ldap = require('ldapjs'); // Create a server const server = ldap.createServer(); server.search('dc=example', (req, res, next) => { const obj = { dn: req.dn.toString(), attributes: { objectclass: ['organization', 'top'], o: 'example' } }; if (req.filter.matches(obj.attributes)) res.send(obj); res.end(); }); server.listen(1389, () => { console.log('LDAP server listening at ' + server.url); }); // Also create a client const client = ldap.createClient({ url: 'ldap://localhost:1389' }); client.bind('cn=root', 'secret', (err) => { if (err) console.error(err); else console.log('bound'); }); client.unbind();
Debug
Known issues
breakingVersion 3.0.0 dropped support for Node.js versions <14. Upgrade Node if using older versions.
fix
Upgrade Node.js to v14 or later.
affects: <3.0.0
breakingIn v3.0.0, LDAP messages and controls are now separate packages (@ldapjs/messages, @ldapjs/controls). Code that directly uses internal message types may break.
fix
Install @ldapjs/messages and @ldapjs/controls as dependencies and import from those packages.
affects: >=3.0.0
gotchaThe default GUID format changed in v2.x; you must set ldap.Attribute.settings.guid_format to enable formatting, otherwise it returns raw buffer.
fix
Set ldap.Attribute.settings.guid_format = ldap.GUID_FORMAT_D before accessing objectGUID.
affects: >=2.0.0
deprecatedThe v2.x branch is no longer receiving updates. Users should migrate to v3.x.
fix
Update to v3.x: npm install ldapjs@latest
affects: <3.0.0
gotchaClient 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.
fix
Use event listeners: client.search() returns a Search object with 'searchEntry' and 'end' events.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot find module 'ldapjs'
ldapjs is not installed or not in node_modules.
fix
Run 'npm install ldapjs' in your project directory.
ldap.Attribute.settings is undefined
Attribute.settings was added in v2.0.0; if you are on v1.x it does not exist.
fix
Upgrade to a newer version: 'npm install ldapjs@latest'
TypeError: server.search is not a function
server.search is a method but may be misspelled; it expects a string DN and a handler.
fix
Check your server setup: ldap.createServer() returns a server object with .search(), .bind(), etc.
Error: Invalid DN
LDAP DNs must be properly formatted (e.g., 'dc=example,dc=com').
fix
Use a valid DN string; escape special characters if needed.
Upgrade
Version history
0.7.1latest on npm
Audit
Dependencies
@ldapjs/messagesrequiredCore dependency for LDAP message encoding/decoding (v3+)
@ldapjs/controlsrequiredCore dependency for LDAP control support (v3+)
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
ldap — npm install ldap · libregistry