bytes
Tiny utility for parsing and formatting byte strings like '1kb'
Repository Health
Technical Analysis
bytes is a single-purpose Node.js utility that converts between numeric byte counts and human-readable byte strings — bytes.format(1024) returns '1KB', and bytes.parse('1kb') returns 1024. It supports the standard binary-prefix units (b, kb, mb, gb, tb, pb, using 1024-based multipliers) plus formatting options for decimal places, thousands separators, and unit separators.
At under 200 lines with zero runtime dependencies, it’s the kind of small, dependable utility that gets pulled in transitively by dozens of larger frameworks (including Express-ecosystem middleware) anywhere a byte size needs to move between a config string and a number.
What You Get
bytes.format(value, options)- convert a byte count into a formatted string like'1.5MB'bytes.parse(value)- convert a byte string like'1kb'back into a numeric byte count- Format options for decimal places, fixed decimals, thousands separator, and unit separator
- Support for all standard binary-prefix units from bytes through petabytes
- Zero runtime dependencies and a small, auditable single-file implementation
Common Use Cases
- Parsing human-friendly config values like
maxFileSize: '10mb'into a numeric byte limit for upload middleware - Displaying human-readable file or transfer sizes in CLI tools and server logs
- Validating request body size limits in HTTP frameworks (used transitively by several Express/Connect body-parsing middlewares)
- Converting between raw byte counts and display strings in dashboards or admin UIs
Under The Hood
Architecture - The entire implementation lives in a single index.js: a fixed map object defines 1024-based multipliers per unit, format() picks the largest unit that fits the magnitude (or uses an explicit options.unit) and formats via toFixed plus optional thousands-separator regex post-processing, while parse() runs a single regex (parseRegExp) to extract a numeric value and unit suffix, falling back to a plain parseInt if the string doesn’t match a unit pattern.
Tech Stack - Plain, dependency-free JavaScript (CommonJS), with a test/ suite and standard .eslintrc linting; no build step is needed since the published package is the source file itself.
Code Quality - The code is compact, well-commented with JSDoc-style annotations for both public functions, and has a long-lived History.md documenting every release since 2012, suggesting careful, incremental maintenance rather than churn; there’s no runtime dependency to audit, which minimizes supply-chain surface area for consumers.
API Design - The API is about as low-friction as a utility can be: one function call in, one value out, with the same default export accepting either a string or number and dispatching accordingly, which is likely why it became a common transitive dependency across body-parsing and HTTP middleware in the Node ecosystem.
Used by 11 apps in this directory
AFFiNE
Productivity · Project Management · Note Taking
Write, draw, and plan in one infinite canvas — the open-source alternative to Notion and Miro that keeps your data yours.
Botpress
AI Assistants · AI Development · Customer Support
The open-source hub for building and deploying LLM-powered AI agents with TypeScript-first tooling, 40+ integrations, and a revolutionary code-execution agent framework.
Directus
CMS · Low Code Platforms
Connect any SQL database and get instant REST and GraphQL APIs, a visual management Studio, and a native MCP server for AI agents — free for most organizations.
Docmost
Productivity · Note Taking · Collaboration
Self-hosted collaborative wiki and knowledge base with real-time editing, diagrams, AI assistance, and enterprise access controls — a modern alternative to Confluence and Notion.
KeystoneJS
CMS · Developer Tools
The superpowered headless CMS for developers built with GraphQL and React
Medplum
Developer Tools · Databases · Authentication
An open-source, FHIR-native healthcare platform that gives developers a compliant backend, authentication, a React component library, and serverless bots to build clinical applications in weeks instead of years.
MLflow
AI Development · Monitoring
The open source AI engineering platform for debugging, evaluating, monitoring, and optimizing production LLMs and agents at scale.
PeerTube
Social Media
A federated, ActivityPub-based video hosting platform built by Framasoft — self-hostable instances interconnect into a network with no vendor lock-in, P2P-assisted streaming, and no ads.
SillyTavern
AI Assistants
The power-user LLM frontend that unifies dozens of AI backends with a rich scripting engine, immersive Visual Novel mode, and a thriving extension ecosystem.