{"id":17642,"library":"express-statsd","title":"StatsD Route Monitoring Middleware for Express","description":"express-statsd is a middleware for Connect and Express applications designed to send route-specific metrics (status codes and response times) to a StatsD server. The current and only stable version is 0.3.0, which was last published over 12 years ago, indicating the project is abandoned. While functional, developers should be aware that it is not actively maintained and may not be compatible with modern Node.js or Express versions without potential issues. Newer, actively maintained alternatives like `express-hot-shots` (a direct fork) or comprehensive monitoring solutions like `express-insights` and `express-status-monitor` offer more features, better compatibility, and ongoing support. This middleware distinguishes itself by its simplicity, focusing solely on basic route-level HTTP metrics.","status":"abandoned","version":"0.3.0","language":"javascript","source_language":"en","source_url":"git://github.com/uber/express-statsd","tags":["javascript","connect","express","statsd","lynx","monitoring"],"install":[{"cmd":"npm install express-statsd","lang":"bash","label":"npm"},{"cmd":"yarn add express-statsd","lang":"bash","label":"yarn"},{"cmd":"pnpm add express-statsd","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Default StatsD client used for sending metrics.","package":"lynx","optional":false}],"imports":[{"note":"This package is CommonJS-only. Use `require()` for Node.js environments. ESM imports will fail unless transpiled or using an interop layer.","wrong":"import expressStatsd from 'express-statsd';","symbol":"expressStatsd","correct":"const expressStatsd = require('express-statsd');"}],"quickstart":{"code":"const express = require('express');\nconst expressStatsd = require('express-statsd');\nconst app = express();\n\n// A helper function to set a custom statsd key per route\nfunction statsd (path) {\n  return function (req, res, next) {\n    const method = req.method || 'unknown_method';\n    req.statsdKey = ['http', method.toLowerCase(), path].join('.');\n    next();\n  };\n}\n\n// Apply the express-statsd middleware globally. \n// Metrics will be generic if req.statsdKey is not set per route.\napp.use(expressStatsd({\n  client: { host: '127.0.0.1', port: 8125 } // Customize StatsD client options\n}));\n\n// Example route with a specific statsd key\napp.get('/', statsd('home'), function (req, res) {\n  res.send('Hello World!');\n});\n\n// Another route with a different statsd key\napp.get('/api/users', statsd('api.users.list'), function (req, res) {\n  res.json([{ id: 1, name: 'Alice' }]);\n});\n\nconst PORT = process.env.PORT || 3000;\napp.listen(PORT, () => {\n  console.log(`Server listening on port ${PORT}`);\n  console.log('Ensure a StatsD daemon is running (e.g., `statsd -p 8125`) to receive metrics.');\n});","lang":"javascript","description":"This example demonstrates how to integrate `express-statsd` globally and, crucially, how to use `req.statsdKey` to namespace metrics per route for more granular monitoring."},"warnings":[{"fix":"Migrate to a maintained alternative such as `express-hot-shots` or a more comprehensive monitoring library like `express-status-monitor` or `express-insights` for long-term stability and security.","message":"The `express-statsd` package is abandoned and has not been updated in over 12 years (last published Feb 12, 2014). It may have compatibility issues with modern Node.js versions (e.g., >=16.x) and recent Express.js major versions (e.g., Express 5.x) due to changes in core APIs or internal middleware mechanics. Consider using actively maintained forks like `express-hot-shots` or alternative monitoring solutions.","severity":"breaking","affected_versions":">=0.3.0"},{"fix":"Implement a middleware or set `req.statsdKey` in your route handler before the response is sent. Example: `req.statsdKey = ['http', req.method.toLowerCase(), 'my_route'].join('.');`","message":"By default, `express-statsd` sends generic 'status_code' and 'response_time' metrics. To get meaningful, route-specific statistics, it is highly recommended to set `req.statsdKey` within your route handlers or a preceding middleware. This namespaces the metrics, providing better insights into individual endpoints.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Ensure your StatsD daemon is actively running and listening on the configured host and port (default: 127.0.0.1:8125). Implement external monitoring for your StatsD daemon and consider adding logging for the `lynx` client's error events if you need more visibility into transmission failures.","message":"The default StatsD client `lynx` (and thus `express-statsd`) relies on UDP for sending metrics. UDP is a 'fire-and-forget' protocol, meaning there's no guarantee of delivery. If your StatsD daemon is not running or is configured incorrectly, metrics will be silently dropped without error feedback from `express-statsd` itself.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"This package is CommonJS-only. Ensure you are using `const expressStatsd = require('express-statsd');` in a CommonJS environment or project configured for CommonJS interop.","cause":"Attempting to import `express-statsd` using ES Modules `import` syntax in a pure ESM project, or incorrect `require()` usage.","error":"TypeError: expressStatsd is not a function"},{"fix":"Run `npm install express-statsd` or `yarn add express-statsd` in your project directory to install the package.","cause":"The package `express-statsd` has not been installed or is not correctly resolved in your project's `node_modules`.","error":"Error: Cannot find module 'express-statsd'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}