{"id":17958,"library":"statsd-parser","title":"Streaming StatsD Protocol Parser","description":"statsd-parser is a Node.js library designed for streaming parsing of the StatsD protocol. It provides both a low-level `parser()` object for direct event-driven parsing and a higher-level `createStream()` API for integrating with Node.js streams, allowing for efficient processing of StatsD metrics from various input sources like network streams or files. The library was last updated in September 2013, with its current and only published version being 0.0.4. Due to its age and lack of maintenance for over a decade, it is not recommended for new projects or existing systems requiring modern Node.js compatibility, security updates, or active support. Key differentiators at the time of its release included its focus on streaming capabilities and event-driven parsing, which was beneficial for handling high-volume metric data efficiently in a Node.js environment.","status":"abandoned","version":"0.0.4","language":"javascript","source_language":"en","source_url":"git://github.com/dscape/statsd-parser","tags":["javascript","statsd","parser","streams","streaming","stats","metrics","lynx"],"install":[{"cmd":"npm install statsd-parser","lang":"bash","label":"npm"},{"cmd":"yarn add statsd-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add statsd-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only, reflecting its age. ES Module imports are not supported.","wrong":"import statsd_parser from 'statsd-parser';","symbol":"statsd_parser","correct":"const statsd_parser = require('statsd-parser');"},{"note":"The `parser` factory function is exposed via the default CommonJS export object, not as a named export.","wrong":"import { parser } from 'statsd-parser';","symbol":"parser","correct":"const statsd_parser = require('statsd-parser');\nconst parser = statsd_parser.parser();"},{"note":"The `createStream` factory function is exposed via the default CommonJS export object, not as a named export.","wrong":"import { createStream } from 'statsd-parser';","symbol":"createStream","correct":"const statsd_parser = require('statsd-parser');\nconst stream = statsd_parser.createStream(options);"}],"quickstart":{"code":"const statsd_parser = require(\"statsd-parser\");\nconst fs = require('fs');\nconst { Readable } = require('stream');\n\n// Basic parser usage\nconst parser = statsd_parser.parser();\n\nparser.onerror = function (e) {\n  console.error(\"Parser Error:\", e.message);\n};\n\nparser.onstat = function (txt, obj) {\n  console.log(`Parsed stat: ${txt} ->`, obj);\n};\n\nparser.onend = function () {\n  console.log(\"Basic parser stream finished.\\n\");\n};\n\nconsole.log(\"--- Using basic parser ---\");\nparser.write('foo.bar:1|c\\nbaz.qux:2.5|g\\n');\nparser.write('timer.event:100|ms\\n');\nparser.close(); // Signal end of input\n\n// Stream usage with a Readable stream\nconst stream = statsd_parser.createStream();\n\nstream.on(\"error\", function (e) {\n  console.error(\"Stream Error:\", e.message); \n  // In a real application, you might need to handle this more robustly,\n  // like clearing the parser error and resuming if it's an internal parser error.\n  this._parser.error = null;\n  this._parser.resume();\n});\n\nstream.on(\"stat\", function (txt, obj) {\n  console.log(`Streamed stat: ${txt} ->`, obj);\n});\n\nstream.on(\"end\", () => {\n  console.log(\"Stream parser finished.\");\n});\n\nconsole.log(\"--- Using stream parser ---\");\nconst inputData = 'metric.one:10|c\\nmetric.two:200|ms\\nmetric.three:3.14|g\\n';\nconst readableStream = Readable.from(inputData);\n\nreadableStream.pipe(stream);\n","lang":"javascript","description":"This quickstart demonstrates both the direct `parser` API and the `createStream` API for processing StatsD metric strings. It shows error handling and how to receive parsed metric objects."},"warnings":[{"fix":"Migrate to an actively maintained StatsD parsing library or a comprehensive observability solution. Examples include `node-statsd-client` (for sending), `telegraf` (for receiving/parsing as a daemon), or modern observability platforms like OpenTelemetry, Prometheus, or Datadog which often include robust StatsD parsing capabilities.","message":"This package is critically unmaintained. The last publish was in 2013 (version 0.0.4) and there has been no development activity for over a decade. It may contain unpatched security vulnerabilities, is unlikely to be compatible with recent Node.js versions, and will not receive bug fixes or new features.","severity":"breaking","affected_versions":">=0.0.4"},{"fix":"Ensure you are using `require()` for importing the library in your Node.js application: `const statsd_parser = require('statsd-parser');`","message":"The package uses a CommonJS module system exclusively. Attempting to use `import` statements will result in runtime errors in environments that enforce ESM-only loading without CommonJS compatibility layers.","severity":"gotcha","affected_versions":"0.0.4"},{"fix":"Implement the recommended error clearing and resumption logic within your `stream.on('error')` handler to maintain stream resilience: \n```javascript\nstream.on(\"error\", function (e) {\n  console.error(\"Error parsing line:\", e.message);\n  this._parser.error = null; // Clear internal parser error state\n  this._parser.resume();     // Allow parser to continue processing\n});\n```","message":"Error handling for the `parser` object requires explicitly clearing the internal error state (`this._parser.error = null; this._parser.resume();`) within the `stream.on('error')` callback to prevent the stream from stopping after the first parsing error. Without this, a single malformed line can halt further processing.","severity":"gotcha","affected_versions":"0.0.4"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Use the standard CommonJS pattern: `const statsd_parser = require('statsd-parser'); const parser = statsd_parser.parser();`","cause":"Attempting to destructure `parser` or `createStream` from a CommonJS `require` call using ES Module syntax.","error":"TypeError: (intermediate value).parser is not a function"},{"fix":"Change your import statement to `const statsd_parser = require('statsd-parser');`","cause":"Using `import statsd_parser from 'statsd-parser'` in an environment where `statsd-parser` is loaded as a CommonJS module and the bundler/runtime doesn't handle the interoperability.","error":"SyntaxError: Unexpected token 'export'"},{"fix":"Ensure the upstream network client or source sending data handles connection stability. For `statsd-parser`, implement robust error handling on the stream (`stream.on('error')`) as shown in the quickstart, and consider using more modern, robust stream processing libraries or network handlers if connection issues are frequent.","cause":"While not directly caused by `statsd-parser` itself, this error can occur when piping network streams (like UDP sockets) that abruptly close or reset the connection, which then affects the `statsd-parser` stream. This package's lack of updates means it won't have modern stream robustness features.","error":"Error: read ECONNRESET"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}