QR code generator for terminal output using ASCII/ANSI characters
npx @tessl/cli install tessl/npm-qrcode-terminal@0.12.0QRCode Terminal generates and displays QR codes directly in the terminal using ASCII/ANSI characters. It provides both a Node.js library API and a command-line interface for creating QR codes from text input, supporting different error correction levels and output formats (normal and compact).
npm install qrcode-terminalconst qrcode = require('qrcode-terminal');const qrcode = require('qrcode-terminal');
// Generate QR code and print to console
qrcode.generate('https://example.com');
// Generate QR code with callback
qrcode.generate('Hello World', function(qrcode) {
console.log(qrcode);
});
// Generate compact QR code
qrcode.generate('Hello World', { small: true });
// Set error correction level
qrcode.setErrorLevel('H');
qrcode.generate('Hello World');Install globally for command-line usage:
npm install -g qrcode-terminalGenerate QR codes from the command line:
# Direct argument
qrcode-terminal "Hello World"
# Piped input
echo "Hello World" | qrcode-terminal
# Help and version
qrcode-terminal --help
qrcode-terminal --versionGenerate QR codes for terminal display with customizable options and output formats.
/**
* Generate QR code and display in terminal or pass to callback
* @param input - Text to encode in QR code
* @param opts - Optional configuration object
* @param cb - Optional callback function to receive QR code string
*/
function generate(input, opts, cb);
/**
* Configuration options for QR code generation
*/
interface GenerateOptions {
/** Generate compact QR code using Unicode block characters */
small?: boolean;
}The generate function supports multiple calling patterns:
generate(input) - Print to consolegenerate(input, callback) - Pass result to callbackgenerate(input, options) - Print with optionsgenerate(input, options, callback) - Pass result with options to callbackSet the error correction level for QR code generation. Higher levels provide better error recovery but result in denser QR codes.
/**
* Set error correction level for subsequent QR code generation
* @param error - Error correction level ('L', 'M', 'Q', or 'H')
*/
function setErrorLevel(error);Built-in error correction level constants available from the library.
/**
* Default error correction level (Low - ~7% recovery)
*/
error: 1;Available Error Correction Levels:
'L' (Low): ~7% error recovery capability (default)'M' (Medium): ~15% error recovery capability'Q' (Quartile): ~25% error recovery capability'H' (High): ~30% error recovery capabilityCommand-line interface for generating QR codes from terminal input.
# Generate QR code from argument
qrcode-terminal <message>
# Generate QR code from piped input
echo <message> | qrcode-terminal
# Display help information
qrcode-terminal --help
qrcode-terminal -h
# Display version number
qrcode-terminal --version
qrcode-terminal -vconst qrcode = require('qrcode-terminal');
// Simple QR code generation
qrcode.generate('Visit https://github.com');const qrcode = require('qrcode-terminal');
qrcode.generate('Hello World', function(qrString) {
// Process the QR code string
console.log('Generated QR code:');
console.log(qrString);
// Save to file, send over network, etc.
});const qrcode = require('qrcode-terminal');
// Generate smaller QR code using Unicode block characters
qrcode.generate('https://example.com', { small: true }, function(qrString) {
console.log('Compact QR code:');
console.log(qrString);
});const qrcode = require('qrcode-terminal');
// Set high error correction for better recovery
qrcode.setErrorLevel('H');
qrcode.generate('Important data that needs high reliability');
// Set low error correction for simpler QR codes
qrcode.setErrorLevel('L');
qrcode.generate('Simple message');# Generate QR code for a URL
qrcode-terminal "https://github.com/gtanner/qrcode-terminal"
# Generate QR code from command output
echo "Hello from the terminal" | qrcode-terminal
# Generate QR code for file contents
cat message.txt | qrcode-terminal