{"id":15949,"library":"alb-log-parser","title":"ALB Log Parser","description":"alb-log-parser is a utility library for Node.js designed to parse Application Load Balancer (ALB) access logs generated by AWS. It provides a function to convert raw ALB log strings into structured JavaScript objects, mapping all fields defined by AWS, including recent additions like `target_group_arn`, `trace_id`, and `classification`. The current stable version is 0.0.8, with the last publish date being July 11, 2021. As a fork of `elb-log-parser`, its release cadence is infrequent, primarily focused on adapting to changes in AWS ALB log formats and improving parsing robustness, such as correctly handling `-1` as a numeric value. It differentiates itself by offering comprehensive field support specifically for ALB logs, making it suitable for serverless architectures (e.g., AWS Lambda) that process logs from S3 buckets for analysis in systems like Elasticsearch.","status":"maintenance","version":"0.0.8","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/igtm/node-alb-log-parser","tags":["javascript","alb","elb","access","log","parser"],"install":[{"cmd":"npm install alb-log-parser","lang":"bash","label":"npm"},{"cmd":"yarn add alb-log-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add alb-log-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package primarily uses CommonJS `module.exports` to export the `parse` function directly. Attempting to destructure it will result in `undefined`.","wrong":"const { parse } = require('alb-log-parser');","symbol":"parse","correct":"const parse = require('alb-log-parser');"},{"note":"While primarily a CommonJS package, modern Node.js environments configured for ESM can import it as a default ESM import. Named imports like `import { parse }` will not work.","wrong":"import { parse } from 'alb-log-parser';","symbol":"parse","correct":"import parse from 'alb-log-parser';"}],"quickstart":{"code":"npm install alb-log-parser\n// or npm install -g alb-log-parser for global CLI usage\n\nconst parse = require('alb-log-parser');\n\nconst albLogLine = 'http 2020-08-27T16:35:00.166351Z app/my-loadbalancer/50dc6c495c0c9188 192.168.131.39:2817 192.168.201.251:80 0.000 0.440 0.000 200 200 1107 11912 \"GET http://example.com:80/path?foo=bar&baz=bak HTTP/1.1\" \"Fake/1.0.0 (Linux)\" - - arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/my-tg/ffffffffffffffff \"Self=1-00000000-111111111111111111111111;Root=1-00000000-222222222222222222222222\" \"-\" \"-\" 0 2020-08-27T16:34:59.725000Z \"forward\" \"-\" \"-\" \"192.168.201.251:80\" \"200\" \"-\" \"-\"';\n\nconst parsedLog = parse(albLogLine);\nconsole.log(JSON.stringify(parsedLog, null, 2));\n\n// Example for accessing specific fields\nconsole.log(`\nClient IP: ${parsedLog.client}`)\nconsole.log(`Request Method: ${parsedLog.request_method}`)\nconsole.log(`Target Status Code: ${parsedLog.target_status_code}`)\n","lang":"javascript","description":"This quickstart demonstrates how to install `alb-log-parser` and use its primary `parse` function to convert a raw ALB access log string into a structured JavaScript object. It shows both installation and basic API usage with a sample log line."},"warnings":[{"fix":"Rely on specific patch versions (e.g., `~0.0.8` instead of `^0.0.8`) or thoroughly test updates before deploying to production environments.","message":"This package is currently in `0.0.x` versioning, indicating a non-stable API. Minor version updates may introduce breaking changes without strictly adhering to semantic versioning guidelines.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Periodically review AWS documentation for ALB log format changes and verify library behavior against new log entries. Consider contributing upstream or migrating if official support or more active development becomes critical.","message":"As a fork of `elb-log-parser`, this package's maintenance and feature development are independent. It may not keep pace with future changes to AWS ALB log formats or new features in the original `elb-log-parser` or other, more actively maintained ALB log parsers in different languages.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Update consumers of the parsed log data to expect numeric `-1` for relevant fields where `\"-\"` previously indicated absence or a non-numeric value. Review pipelines that perform strict type checking or rely on the previous string representation.","message":"In `v0.0.8`, the parser was updated to interpret fields with the value `\"-1\"` as a numeric `-1` instead of a string `\"-\"`. While intended as a correction, this changes the data type and value for these specific fields, potentially affecting existing data processing pipelines or schema expectations.","severity":"breaking","affected_versions":">=0.0.8"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Use `const parse = require('alb-log-parser');` for CommonJS or `import parse from 'alb-log-parser';` for ESM to correctly import the default exported function.","cause":"Attempting to destructure a default export, e.g., `const { parse } = require('alb-log-parser');` or `import { parse } from 'alb-log-parser';`, when the module exports the function directly as the default export.","error":"TypeError: parse is not a function"},{"fix":"Switch to ESM import syntax: `import parse from 'alb-log-parser';` if your project is configured for ES Modules.","cause":"Attempting to use CommonJS `require()` syntax in an ES Module (`.mjs` file or `\"type\": \"module\"` in `package.json`) context.","error":"ReferenceError: require is not defined"}],"ecosystem":"npm"}