qrcode
A zero-dependency-on-canvas QR code and 2D barcode generator for Node.js and the browser.
Repository Health
Technical Analysis
qrcode is an npm library for generating QR codes and 2D barcodes from server-side Node.js code or directly in the browser. It builds the QR symbol from scratch (segment optimization, Reed-Solomon error correction, mask-pattern selection) and ships pluggable renderers that can output the result as a PNG file or buffer, an SVG string, a data URL, raw terminal text, or directly onto an HTML5 canvas element.
Both a callback-based and a Promise/async-await API are supported for every render target, and the package also installs a qrcode CLI binary so a QR code can be generated or previewed from a shell one-liner without writing any code.
What You Get
- A spec-compliant QR Code encoder supporting Numeric, Alphanumeric, Kanji, and Byte modes with automatic mixed-mode segmentation for the smallest possible symbol
- Renderers for canvas, PNG (file, buffer, or data URL), SVG, UTF-8/terminal text, and writable file streams
- A dual callback/Promise API across every render function (
toDataURL,toBuffer,toFile,toFileStream,toString,toCanvas) - A globally installable
qrcodeCLI for generating QR images or previewing them directly in the terminal - Configurable error correction levels (L/M/Q/H), symbol version, mask pattern, quiet zone, and custom foreground/background colors
Common Use Cases
- Generating login/2FA QR codes (e.g. TOTP
otpauth://URIs) for authenticator app enrollment - Rendering shareable QR codes for URLs, contact cards, or Wi-Fi credentials on server-rendered pages or PDFs
- Embedding scannable payment or ticket codes in receipts and event passes generated as PNG/SVG assets
- Client-side QR generation directly onto a
<canvas>element for real-time previews as a user types
Under The Hood
Architecture — The encoder lives entirely under lib/core/ as a pipeline of small, single-purpose modules: segments.js splits input into Numeric/Alphanumeric/Kanji/Byte runs, version.js picks the smallest QR version that fits, bit-buffer.js and reed-solomon-encoder.js/polynomial.js/galois-field.js build and error-correct the codeword stream, and qrcode.js (createSymbol) assembles the final BitMatrix by laying down finder, timing, alignment, and format-info patterns before mask-pattern.js scores all eight masks and applies the best one. lib/index.js (Node) and lib/browser.js (browser) are thin adapters that call QRCode.create() and hand the resulting matrix to one of five interchangeable renderers under lib/renderer/ (canvas, png, svg, terminal, utf8), so the same core encoder drives every output format.
Tech Stack — Runtime dependencies are minimal and purpose-built: pngjs for PNG encoding, dijkstrajs for shortest-path segment-mode optimization, and yargs for the CLI’s argument parsing. The browser bundle is produced via Rollup with Babel’s preset-env, and standard enforces lint rules as a pretest hook, so a broken style fails CI before tests even run.
Code Quality — Test coverage is thorough and organized to mirror the source layout: 26 unit test files under test/unit/core and test/unit/renderer exercise each internal module in isolation (bit-buffer, mask-pattern, reed-solomon-encoder, etc.), while test/e2e/*.test.js drives the public toCanvas/toDataURL/toFile/toFileStream/toString API end-to-end using tap and sinon. Functions are short, consistently documented with JSDoc blocks, and side effects (like the mutable toSJISFunc set on Utils) are the rare exception rather than the norm.
API Design — The public surface is deliberately small and uniform: every to* render function accepts the same (data, options, callback) shape and transparently returns a Promise when the callback is omitted, so consumers opt into whichever async style fits their codebase without adapter code. Getting a QR code onto the screen or into a file takes one line (QRCode.toDataURL(text, cb)), and the same mental model extends to the CLI binary, keeping the learning curve low for a spec-heavy domain.
Used by 54 apps in this directory
rowboat
AI Assistants · AI Development
Build, test, and deploy multi-agent AI workflows with a visual editor, RAG data sources, MCP tool integration, and a production-ready REST API.
Shadowbroker
Analytics · Monitoring · Security
Self-hosted OSINT dashboard that fuses 60+ live intelligence feeds — flight tracking, ship AIS, satellites, CCTV, seismic and radio networks — into one real-time map, with an agent-ready command channel for AI co-analysts.
Spacedrive
Collaboration · File Storage
One file manager for all your devices and clouds — powered by a Virtual Distributed File System built in Rust.
Hexclave
Authentication · Developer Tools
The open-source user infrastructure platform — authentication, teams, payments, emails, analytics, and more on a single unified user model.
Termix
Devops
Manage all your servers — SSH terminals, remote desktops, file transfers, and Docker containers — from a single self-hosted browser interface.
Typebot
AI Assistants · AI Development · Developer Tools
Build sophisticated chatbots visually, embed them anywhere without iframes, and own your data — fully self-hostable with a modular block system and 30+ integrations.
Uptime Kuma
Monitoring
Self-hosted monitoring for every service you run — 23 monitor types, 95 notification channels, live dashboards, and public status pages with no vendor lock-in.
VoiceStudio
Mcp · Music Audio · Voice AI
Open-source, fully local ElevenLabs alternative for voice cloning, voice design, video dubbing, dictation, transcription and audiobooks, with a local API and MCP server for agents.
VoidAuth
Authentication · Security
Self-hosted SSO with OIDC, LDAP, passkeys, and proxy auth for your entire self-hosted stack