qrcode (JavaScript)
Generate QR codes on server and client using canvas with Node.js and browser support.
2. Maintained
github.com/soldair/node-qrcode3. Used by agents' projects
Dependency in 124 public GitHub projects set up for AI coding agents that we scanned (2.0%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What qrcode (JavaScript) does
qrcode splits your input into mixed-mode segments by default to get the shortest bitstream. The same package draws QR codes to a canvas in the browser, writes PNG or SVG files on a server, and prints them in a terminal from its CLI.
qrcode (JavaScript) popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How qrcode (JavaScript) is used
- qrcode (JavaScript) is a dependency in 124 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (2.5% of the 4,867 JavaScript/TypeScript ones), #6 of 281 in files, images and media.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 397; those are left out of every share on this page.
- Projects that use it most often also use Zod (71.8%), React (74.2%), tsx (50.8%).
By coding agent
Often used with
qrcode (JavaScript) in practice
Strengths
By default the input string is split into segments, each in the mode that keeps the bitstream shortest. The library supports Numeric, Alphanumeric, Kanji and Byte modes. The README's example <code>ABCDE12345678?A1A</code> becomes Alphanumeric, Numeric and Byte segments. The README calls auto mode "the preferred way to generate the QR Code".
You can load it through Browserify or Webpack, or as a precompiled script from the <code>build/</code> folder. The README says that bundle supports Internet Explorer 10+, Safari 5.1+ and all evergreen browsers.
If you install it globally, <code>qrcode "some text"</code> draws the code in the terminal. Adding <code>-o out.png</code> saves a file. The output type is guessed from the <code>png</code>, <code>svg</code> or <code>txt</code> extension.
<code>toDataURL</code> defaults to <code>image/png</code> and can also return <code>image/jpeg</code> or <code>image/webp</code>. For the two lossy formats, a quality setting between 0 and 1 is available, with a default of 0.92.
Watch out for
Converting bytes to a JavaScript string first breaks the encoding. Pass a <code>Uint8ClampedArray</code>, a compatible array or a Node Buffer in a <code>byte</code> segment instead. The README also warns that element values are clamped to 0-255.
The <code>@types/qrcode</code> typings expect <code>data: string</code>. Passing binary data from TypeScript therefore needs a <code>// @ts-ignore</code> above the data segment.
The Shift JIS conversion table is left out of the default bundle. To use Kanji mode, pass <code>toSJISFunc</code>, either from <code>qrcode/helper/to-sjis</code> or from the separate <code>qrcode.tosjis.min.js</code> file. Without it, kanji can still be encoded in Byte mode.
Generate a data URL with promises or async/await
import QRCode from 'qrcode'
// With promises
QRCode.toDataURL('I am a pony!')
.then(url => {
console.log(url)
})
.catch(err => {
console.error(err)
})
// With async/await
const generateQR = async text => {
try {
console.log(await QRCode.toDataURL(text))
} catch (err) {
console.error(err)
}
}More about qrcode (JavaScript)
Packages around it
- zod: Schema validation
- lucide-react: React icon set
- vitest: Test runner
- tailwind-merge: Tailwind class merging
- react: UI library
- clsx: className builder
Alternatives
qrcode (JavaScript) This page
Get started
Install it.
npm install qrcodeRules for your agent
## qrcode
- Leave encoding to auto mode and omit `version`. The README says the version option is not needed unless a specific version is required.
- Pass binary payloads as `[{ data: <Uint8ClampedArray or Buffer>, mode: 'byte' }]`, never as a string. Values are clamped to 0-255.
- With `@types/qrcode`, put `// @ts-ignore` above a binary data segment, because the types expect `data: string`.
- Set `errorCorrectionLevel` deliberately. The default is `M`. The README says a low level such as `L` or `M` is safe for codes shown on a monitor. Higher levels reduce capacity.
- Use `toFile` and `toFileStream` only on the server. In the browser use `toCanvas`, `toDataURL`, `toString` or `create`.
- For Kanji-mode compression, pass `toSJISFunc` from `qrcode/helper/to-sjis`. Otherwise encode kanji in Byte mode.
- Promises and async/await can replace the callback. Handle errors with `.catch` or `try`/`await`.