Employee Spotlight
From Academia to Industry
Philipp Burckhardt recounts his journey from childhood computer fascinations, to building an e-learning platform at Carnegie Mellon University, and on to his current role at Socket.
qrcode
Advanced tools
QRCode / 2d Barcode api with both server side and client side support using canvas
Package description
The qrcode npm package is a library for generating QR codes. It can be used to create QR codes in various formats such as images or canvas for web applications, and it supports a range of customization options.
Generating QR Code as Data URL
This feature allows you to generate a QR code as a data URL, which can be used directly in image tags or CSS backgrounds.
const QRCode = require('qrcode');
QRCode.toDataURL('https://www.example.com', function (err, url) {
console.log(url);
});
Generating QR Code as PNG Image File
This feature allows you to generate a QR code and save it as a PNG image file on the filesystem.
const QRCode = require('qrcode');
QRCode.toFile('path/to/output.png', 'https://www.example.com', function (err) {
if (err) throw err;
console.log('QR Code saved as image file!');
});
Generating QR Code as UTF8 String
This feature allows you to generate a QR code as a UTF8 string, which can be printed to the terminal or used in text-based formats.
const QRCode = require('qrcode');
QRCode.toString('https://www.example.com', { type: 'terminal' }, function (err, string) {
if (err) throw err;
console.log(string);
});
The qrcode-svg package generates QR codes in SVG format. It offers a different output format compared to qrcode and might be preferred when working with vector graphics.
The qr-image package is another alternative for generating QR codes. It can create QR codes in PNG, SVG, EPS, and PDF formats. It provides a different API and additional output formats compared to qrcode.
Unlike qrcode, which is focused on generating QR codes, jsQR is a library for parsing and reading QR codes. It is used to decode QR codes from images.
Readme
This is a node js server side QR code / 2d barcode generator. it is an extension of "QRCode for JavaScript" which Kazuhiko Arase thankfully mit licensed
the qrcode-draw.js can be used directly as a client side lib if its appended too or included with lib/qrcode.js to use this on the server side please require('qrcode'); =)
this libary can encode a string up to lengths: 2953 in error correct level L 2331 in error correct level M 1663 in error correct level Q 1273 in error correct level h
the default is H. It can now be changed in an ugly way that wont be supported for more then another few days if you really need to. also the default module size at qr version 40 is really too small for the camera on my Nexus 1 and to make it larger i run out of screen to show it. At 40 the barcode scanner even finds random UPC 1d barcodes in the mass of little squares. the default module size cannot be changed through the public api at this time.
npm install qrcode
QRCode.draw(text,cb(error,canvas));
returns node canvas object see https://github.com/LearnBoost/node-canvas for all of the cool node things you can do
look up the canvas api for the other cool things
QRCode.toDataURL(text,cb(error,dataURL));
returns mime image/png data url for the 2d barcode
QRCode.save(path,text,cb(error,written));
saves png to the path specified returns bytes written
simple test
var sys = require('sys');
var QRCode = require('qrcode');
QRCode.toDataURL('i am a pony!',function(err,url){
sys.print(url);
});
in bash
node ./tests/url.js
for server use: see tests/server.js
for client side use: open tests/clientside.html in your browser or run tests/clientsideserver.js yes, it really works in the browser. new browsers but yeah it works. for bad ones perhaps try excanvas?
these should be taken care of for you by npm but you should
npm install canvas
if cairo gives you trouble and you cannot install canvas checkout the canvas site i know tj has setup a way to download and install a version of cairo/pixman for testing.
The word "QR Code" is registered trademark of DENSO WAVE INCORPORATED
FAQs
QRCode / 2d Barcode api with both server side and client side support using canvas
The npm package qrcode receives a total of 1,984,584 weekly downloads. As such, qrcode popularity was classified as popular.
We found that qrcode demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Employee Spotlight
Philipp Burckhardt recounts his journey from childhood computer fascinations, to building an e-learning platform at Carnegie Mellon University, and on to his current role at Socket.
Security News
Git dependencies in open source packages can introduce significant risks, including lack of version control, stability issues, dependency drift, and difficulty in auditing, making them potential targets for supply chain attacks.
Security News
Node.js has added experimental support for TypeScript, a move that highlights the growing importance of TypeScript in modern development.