{"id":16080,"library":"http-string-parser","title":"HTTP String Parser","description":"http-string-parser is a lightweight, proof-of-concept library designed to parse raw HTTP request and response messages from strings within Node.js environments. The package is currently at version 0.0.6, with its last known update in 2014, indicating it is no longer actively maintained. Its core functionality offers methods like `parseRequest`, `parseResponse`, `parseRequestLine`, `parseStatusLine`, and `parseHeaders` to break down HTTP messages into structured JavaScript objects. A key differentiator is its explicit admission of being a 'naive' parser, not leveraging Node.js core's C bindings for HTTP parsing or more robust alternatives like `http-pegjs`, which were even suggested as future replacements in its own README. It serves as a basic utility for scenarios where a simple, non-production-grade parsing of well-formed HTTP strings is sufficient, but lacks the robustness and ongoing support expected for modern applications.","status":"abandoned","version":"0.0.6","language":"javascript","source_language":"en","source_url":"https://github.com/apiaryio/http-string-parser","tags":["javascript","http","message","request","response","parser","string","raw","bare"],"install":[{"cmd":"npm install http-string-parser","lang":"bash","label":"npm"},{"cmd":"yarn add http-string-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-string-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is CommonJS-only and has not been updated since 2014. ESM `import` statements are not supported directly without a transpilation layer or explicit CommonJS wrapping.","wrong":"import parser from 'http-string-parser';","symbol":"parser","correct":"const parser = require('http-string-parser');"},{"note":"While CommonJS allows direct destructuring from `require`, the primary API pattern presented in the documentation is accessing methods via the `parser` object (`parser.parseRequest`). Direct destructuring works as the module exports an object containing these functions.","wrong":"import { parseRequest } from 'http-string-parser';","symbol":"parseRequest","correct":"const { parseRequest } = require('http-string-parser');"},{"note":"Similar to `parseRequest`, `parseResponse` is a method on the default exported object. Direct `import` from ES modules will fail.","wrong":"import { parseResponse } from 'http-string-parser';","symbol":"parseResponse","correct":"const parser = require('http-string-parser');\nconst response = parser.parseResponse(responseString);"}],"quickstart":{"code":"const parser = require('http-string-parser');\n\nconst httpRequestString = `GET /api/data?id=123 HTTP/1.1\\r\\nHost: example.com\\r\\nUser-Agent: NodeParser/1.0\\r\\nContent-Type: application/json\\r\\nContent-Length: 20\\r\\n\\r\\n{\"message\": \"hello\"}`;\n\nconst httpResponseString = `HTTP/1.1 200 OK\\r\\nContent-Type: application/json\\r\\nContent-Length: 22\\r\\n\\r\\n{\"status\": \"success\"}`;\n\ntry {\n  console.log('Parsing HTTP Request:');\n  const request = parser.parseRequest(httpRequestString);\n  console.log(JSON.stringify(request, null, 2));\n\n  console.log('\\nParsing HTTP Response:');\n  const response = parser.parseResponse(httpResponseString);\n  console.log(JSON.stringify(response, null, 2));\n} catch (error) {\n  console.error('An error occurred during parsing:', error.message);\n}","lang":"javascript","description":"Demonstrates parsing a raw HTTP request and response string into structured JavaScript objects using the `parseRequest` and `parseResponse` methods."},"warnings":[{"fix":"Consider using actively maintained alternatives like `node:http` built-in parsers (for server-side) or more robust third-party libraries for client-side or generic HTTP message parsing.","message":"This package is effectively abandoned, with its last commit in 2014 and version 0.0.6. It is not compatible with modern Node.js versions out-of-the-box (e.g., ESM modules) and lacks ongoing maintenance for security vulnerabilities or bug fixes.","severity":"breaking","affected_versions":">=0.0.1"},{"fix":"Evaluate your parsing requirements carefully. For production-grade HTTP parsing, refer to the `http-parser` used by Node.js core, or well-established HTTP client/server frameworks that encapsulate robust parsing logic.","message":"The README explicitly states this is a 'proof of concept, naive HTTP parsing, wheel re-invention.' It does not handle complex HTTP features, malformed requests, or edge cases robustly. Do not use for production systems requiring resilience or full RFC compliance.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Favor `http-parser` (used internally by Node.js) or `http-pegjs` if you need string-based parsing with better compliance and performance.","message":"The package's own README suggests it 'may be replaced with better parser from [Node.JS core's C bindings of NGINX HTTP parser] or [PEG.js HTTP parser]'. This indicates it was always intended as a temporary or educational solution.","severity":"deprecated","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure you are using `const parser = require('http-string-parser');` and then calling `parser.parseRequest(...)` or `parser.parseResponse(...)`.","cause":"Attempting to call `parseRequest` without correctly requiring the module as a CommonJS object, or trying to destructure incorrectly.","error":"TypeError: parser.parseRequest is not a function"},{"fix":"Convert your file to CommonJS (`const parser = require('http-string-parser');`) or properly configure your project to use ES Modules (e.g., by adding `\"type\": \"module\"` to `package.json`), although this package's core functionality is not designed for ESM.","cause":"Trying to use `import` syntax (`import parser from 'http-string-parser';`) in a Node.js project configured for CommonJS modules.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"This package is not designed for robust parsing. For complex HTTP scenarios, switch to a more mature and compliant HTTP parsing library or the `node:http` module.","cause":"The parser is 'naive' and does not implement full HTTP RFC compliance, leading to failures or partial parsing for complex or non-standard HTTP messages.","error":"Parsing results are incomplete or incorrect for specific HTTP messages (e.g., chunked encoding, unusual headers)."}],"ecosystem":"npm"}