{"library":"speedometer","title":"Simple JavaScript Speedometer","type":"library","description":"Speedometer is a lightweight JavaScript utility designed for measuring throughput in bytes per second over a sliding time window. It is particularly useful in Node.js environments for tracking data transfer rates, such as file streaming or network activity. The current stable version is 1.1.0, and the package appears to be in a maintenance state, with infrequent updates primarily for tooling rather than new features or significant API changes. Its key differentiator lies in its extreme simplicity and low-level focus, providing a raw numerical measurement without UI components, contrasting with many other 'speedometer' packages that offer graphical gauges for web frameworks. Users can configure the buffer duration for averaging speed, which defaults to 5 seconds, allowing for flexible measurement intervals.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install speedometer"],"cli":null},"imports":["const speedometer = require('speedometer')"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/mafintosh/speedometer","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/speedometer","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"const speedometer = require('speedometer');\nconst fs = require('fs');\n\n// Create a speedometer instance with a 10-second buffer\nconst speed = speedometer(10);\nconst stream = fs.createReadStream('/dev/urandom', { highWaterMark: 1024 * 1024 }); // Read in 1MB chunks\n\nlet totalBytes = 0;\nlet lastLogTime = Date.now();\n\nstream.on('data', function(data) {\n  // Pass the amount of bytes transferred to the speedometer\n  const bytesPerSecond = speed(data.length);\n  totalBytes += data.length;\n\n  // Log speed every second\n  if (Date.now() - lastLogTime >= 1000) {\n    console.log(`Current speed: ${bytesPerSecond.toFixed(2)} bytes/second`);\n    lastLogTime = Date.now();\n  }\n});\n\nstream.on('end', () => {\n  console.log(`\nFinished reading. Total bytes: ${totalBytes}`);\n  const finalSpeed = speed(); // Get current speed one last time\n  console.log(`Final calculated speed (over buffer): ${finalSpeed.toFixed(2)} bytes/second`);\n});\n\nstream.on('error', (err) => {\n  console.error('Stream error:', err);\n});","lang":"javascript","description":"This example demonstrates how to initialize the speedometer, feed it data chunk lengths, and continuously log the calculated bytes per second for a data stream.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}