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.
httpMessageParser
✓ const httpMessageParser = require('http-message-parser');
✗ import httpMessageParser from 'http-message-parser';
This library is primarily CommonJS and does not officially support ESM. Direct ESM import might fail or require a CommonJS wrapper.
parseHttpMessage
✓ const parseHttpMessage = require('http-message-parser');
The default export (or module.exports) is the parsing function itself.
httpMessageParserCli
✓ # CLI usage as shown in documentation
The package also exposes a command-line interface, not typically imported as a symbol but used via `http-message-parser <file>` or piping input.
This quickstart demonstrates parsing a multi-part HTTP response from a Buffer and then inspecting its structured output, including decoding one of the multipart bodies.
const httpMessageParser = require('http-message-parser');
const fs = require('fs');
const path = require('path');
const exampleMessage = [
'HTTP/1.1 200 OK',
'MIME-Version: 1.0',
'Content-Type: multipart/mixed; boundary=frontier',
'',
'This is a message with multiple parts in MIME format.',
'--frontier',
'Content-Type: text/plain',
'',
'This is the body of the message.',
'--frontier',
'Content-Type: application/octet-stream',
'Content-Transfer-Encoding: base64',
'',
'PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogICAgPHA+VGhpcyBpcyB0aGUg',
'Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg==',
'--frontier--'
].join('\r\n');
// Simulate reading from a file or network stream with a Buffer
const messageBuffer = Buffer.from(exampleMessage, 'binary');
console.log('Parsing HTTP message...');
const parsedMessage = httpMessageParser(messageBuffer);
console.log(JSON.stringify(parsedMessage, (key, value) => {
// Convert Buffer to string for display, or indicate its presence
if (value && typeof value === 'object' && value.type === 'Buffer') {
return `<Buffer(${value.data.length} bytes)>`;
}
return value;
}, 2));
// Accessing specific parts
if (parsedMessage.multipart && parsedMessage.multipart.length > 0) {
const firstPartBody = parsedMessage.multipart[0].body;
console.log('\nFirst multipart body (decoded):', firstPartBody.toString('utf8'));
}
Debug
Known issues
breakingThe library primarily targets Node.js versions >=0.10.0 (circa 2012) and has not been updated since 2018. It may not be fully compatible with modern Node.js features, ES modules, or recent changes in HTTP standards or Buffer API behavior.fixConsider alternative, actively maintained HTTP parsing libraries for modern Node.js applications or thoroughly test compatibility before production deployment. Ensure a CommonJS environment.
affects: >=0.0.35 (hypothetical), or running on Node.js >=12
gotchaAll message bodies (main body and multipart bodies) are returned as Node.js Buffer objects to preserve original encoding. This requires explicit conversion to string (e.g., `body.toString('utf8')`) if text is expected, or special handling for binary data.fixAlways check `typeof body === 'object' && body.type === 'Buffer'` and use `body.toString('encoding')` or other Buffer methods as appropriate. In browser environments, a `Buffer` polyfill like `feross/buffer` is required for binary data handling. affects: >=0.0.1
gotchaThe package uses `require()` and does not explicitly support ES Modules (ESM). Attempting to `import` it directly in an ESM context might lead to errors or unexpected behavior unless specific Node.js interop flags are used.fixUse CommonJS `require()` for importing the library. If absolutely necessary in an ESM project, use dynamic `import()` or review Node.js's CJS-ESM interop documentation.
affects: >=0.0.1
Errors
Common errors & fixes
httpMessageParser is not a function
Attempting to import the module incorrectly in an ESM context or trying to destructure a non-object export.
fixEnsure you are using `const httpMessageParser = require('http-message-parser');` in a CommonJS module or environment. Buffer is not defined
Using the library in a browser environment without providing a `Buffer` polyfill.
fixInstall and configure a `Buffer` polyfill (e.g., `npm install buffer` and import it) for browser environments when dealing with binary data.
TypeError: Cannot read properties of undefined (reading 'headers')
Attempting to access properties like 'headers' or 'body' on a `parsedMessage` object that might be `null` or have an unexpected structure if the input message was malformed or empty.
fixAlways check the `parsedMessage` object and its sub-properties (e.g., `parsedMessage && parsedMessage.headers`) for existence before accessing them, especially when handling arbitrary or potentially invalid input.
Audit
Dependencies
No dependency data recorded yet.