Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
createType1Message
✓ const { createType1Message } = require('ntlm-client');
✗ import { createType1Message } from 'ntlm-client';
Package is CommonJS-only; direct ESM imports are not supported.
decodeType2Message
✓ const { decodeType2Message } = require('ntlm-client');
✗ import decodeType2Message from 'ntlm-client';
Package is CommonJS-only and exports named functions.
createType3Message
✓ const { createType3Message } = require('ntlm-client');
✗ import * as ntlmClient from 'ntlm-client';
Access named exports directly from the CommonJS module.
This example demonstrates a conceptual NTLM Type 1, Type 2, and Type 3 message exchange using the core functions, simulating interaction with an NTLM-protected server using native Node.js `http` module. Set NTLM_SERVER_URL, NTLM_USERNAME, NTLM_PASSWORD environment variables for a real NTLM server.
const { createType1Message, decodeType2Message, createType3Message } = require('ntlm-client');
const http = require('http'); // Using native http for demonstration
const NTLM_SERVER_URL = process.env.NTLM_SERVER_URL ?? 'http://localhost:8080/protected';
const USERNAME = process.env.NTLM_USERNAME ?? 'user';
const PASSWORD = process.env.NTLM_PASSWORD ?? 'pass';
const WORKSTATION = process.env.NTLM_WORKSTATION ?? require('os').hostname();
const DOMAIN = process.env.NTLM_DOMAIN ?? '';
async function performNtlmHandshake() {
let type1Msg = createType1Message(WORKSTATION, DOMAIN);
console.log('Sending Type 1 message...');
// Step 1: Send Type 1 message
let response1 = await sendHttpRequest(NTLM_SERVER_URL, 'GET', { 'Authorization': `NTLM ${type1Msg}` });
if (response1.statusCode === 401 && response1.headers['www-authenticate']) {
const wwwAuthenticateHeader = response1.headers['www-authenticate'];
const type2Match = wwwAuthenticateHeader.match(/NTLM (.*)$/);
if (type2Match && type2Match[1]) {
console.log('Received Type 2 message. Decoding...');
let type2Msg = decodeType2Message(type2Match[1]);
let type3Msg = createType3Message(type2Msg, USERNAME, PASSWORD, WORKSTATION, DOMAIN);
console.log('Sending Type 3 message...');
// Step 2: Send Type 3 message
let response2 = await sendHttpRequest(NTLM_SERVER_URL, 'GET', { 'Authorization': `NTLM ${type3Msg}` });
if (response2.statusCode === 200) {
console.log('NTLM authentication successful!');
console.log('Response body:', response2.body.toString().substring(0, 100) + '...');
} else {
console.error('NTLM authentication failed at Type 3 stage. Status:', response2.statusCode);
}
} else {
console.error('No NTLM Type 2 message found in WWW-Authenticate header.');
}
} else if (response1.statusCode === 200) {
console.log('No NTLM authentication required. Request successful.');
console.log('Response body:', response1.body.toString().substring(0, 100) + '...');
} else {
console.error('Initial request failed or NTLM not initiated. Status:', response1.statusCode);
}
}
function sendHttpRequest(url, method, headers) {
return new Promise((resolve, reject) => {
const client = http.request(url, { method, headers }, (res) => {
let body = [];
res.on('data', (chunk) => body.push(chunk));
res.on('end', () => {
resolve({ statusCode: res.statusCode, headers: res.headers, body: Buffer.concat(body) });
});
});
client.on('error', reject);
client.end();
});
}
performNtlmHandshake().catch(console.error);
Errors
Common errors & fixes
Cannot find module 'request'
The package's `request` convenience function depends on the `request` npm module, which must be installed separately, or was not resolved correctly by the package manager.
fixInstall the `request` dependency explicitly: `npm install request`. However, it is highly recommended to avoid the deprecated `request` function and instead use the core NTLM message functions with a modern HTTP client.
TypeError: createType1Message is not a function
This error typically occurs when attempting to use ES Module `import` syntax with a CommonJS-only package, or when trying to destructure a module that exports functions directly rather than as named exports from a default object.
fixEnsure you are using CommonJS `require` syntax: `const { createType1Message } = require('ntlm-client');`. Audit
Dependencies
requestrequiredUsed by the convenience `request(options)` function for making authenticated HTTP calls. This dependency is now deprecated.