Supported Barcode Types
Quagga2 supports a wide variety of 1D barcode formats. This page lists all available barcode readers and how to configure them.
Available Readers
Quagga2 includes built-in readers for the following barcode formats:
| Reader Name | Barcode Format | Common Uses |
|---|---|---|
code_128_reader |
Code 128, GS1-128 | General purpose, shipping, packaging, supply chain |
ean_reader |
EAN-13 | Retail products worldwide |
ean_8_reader |
EAN-8 | Small retail products |
code_39_reader |
Code 39 | Automotive, defense, healthcare |
code_39_vin_reader |
Code 39 VIN | Vehicle Identification Numbers |
codabar_reader |
Codabar | Libraries, blood banks, logistics |
upc_reader |
UPC-A | Retail products (North America) |
upc_e_reader |
UPC-E | Small retail products |
i2of5_reader |
Interleaved 2 of 5 | Warehouse, distribution |
2of5_reader |
Standard 2 of 5 | Industrial, airline tickets |
code_93_reader |
Code 93 | Logistics, retail |
code_32_reader |
Code 32 | Italian pharmaceuticals |
pharmacode_reader |
Pharmacode | Pharmaceutical packaging |
Basic Configuration
Specify which barcode types to detect in the decoder.readers array:
Quagga.init({
decoder: {
readers: ["code_128_reader"] // Only detect Code 128
}
}, function(err) {
if (err) {
console.error(err);
return;
}
Quagga.start();
});
Multiple Readers
You can enable multiple readers to detect different barcode types:
Quagga.init({
decoder: {
readers: [
"code_128_reader",
"ean_reader",
"upc_reader"
]
}
});
Important Considerations
Reader Priority and Order
Readers are processed in the exact order they appear in the readers array. The first reader to successfully decode the barcode wins - subsequent readers are not tried.
This allows you to prioritize certain formats over others when multiple formats might match the same barcode pattern:
decoder: {
// EAN-13 checked first, then UPC formats
readers: ['ean_reader', 'upc_reader', 'upc_e_reader']
}
Why order matters:
- Readers are processed sequentially, not in parallel
- Some readers may return false positives for other formats
- Example: EAN-13 and UPC-A/UPC-E share similar patterns and can clash
- The first successful decode is returned immediately
Best practice: List your most commonly expected barcode types first for best accuracy and performance.
Don’t Enable All Readers
Why not enable all readers by default?
- More readers = more processing time
- Increased chance of false positives
- Some formats overlap and can interfere
Best practice: Only enable the barcode formats you actually need to scan.
Format Conflicts
Some barcode formats are subsets or extensions of others:
- UPC-A is a subset of EAN-13
- EAN-8 is shorter version of EAN-13
- Code 39 and Code 39 VIN share similar patterns
Be careful when enabling multiple related formats together.
GS1-128 Barcodes
GS1-128 (formerly known as EAN-128 or UCC-128) is a subset of Code 128 used extensively in supply chain and logistics. It uses special FNC1 (Function Code 1) characters to separate variable-length data fields called Application Identifiers (AIs).
How GS1-128 Works
GS1-128 barcodes encode structured data using standardized Application Identifiers. For example:
- AI 01 = GTIN (Global Trade Item Number)
- AI 10 = Batch/Lot Number
- AI 17 = Expiration Date
- AI 21 = Serial Number
The FNC1 character acts as a field separator between variable-length AIs, allowing decoders to know where one field ends and another begins.
FNC1 Character Handling
When the code_128_reader decodes a GS1-128 barcode, FNC1 characters are represented as ASCII 29 (Group Separator, \x1D or \u001d). This follows the GS1 standard for representing FNC1 in decoded data.
Quagga.decodeSingle({
src: 'gs1-128-barcode.jpg',
decoder: {
readers: ['code_128_reader']
}
}, function(result) {
if (result && result.codeResult) {
const code = result.codeResult.code;
// FNC1 characters appear as ASCII 29 (Group Separator)
const GS = String.fromCharCode(29); // '\x1D'
// Split on Group Separator to get individual AI fields
const fields = code.split(GS);
console.log('Fields:', fields);
// Example output: ["", "01034531200000111719050810ABCD1234", ...]
// Or check for GS1-128 format (starts with FNC1)
if (code.startsWith(GS)) {
console.log('This is a GS1-128 barcode');
}
}
});
Parsing GS1-128 Data
Once decoded, you can parse the GS1-128 data using the Application Identifier structure:
function parseGS1(code) {
const GS = String.fromCharCode(29);
// Remove leading FNC1 if present
const data = code.startsWith(GS) ? code.substring(1) : code;
// Split by FNC1 separator
const segments = data.split(GS);
// Parse each segment for its AI
// (A full implementation would use a complete AI table)
return segments;
}
For full GS1 parsing, consider using a dedicated library like gs1-barcode-parser after decoding with Quagga2.
EAN Extensions
EAN-2 and EAN-5 Supplements
The EAN and UPC barcode formats support a supplement format, adding an additional 2 or 5 digits beyond the main barcode, EAN-2 and EAN-5, respectively. They are typically used for:
- Magazines and periodicals: The main barcode identifies the publication, while the supplement denotes issue numbers or publication dates
- Books with ISBN: The 5-digit supplement often encodes the suggested retail price
By default, ean_reader does not read and decode these extensions, you must explicitly enable support for them, if you are looking for them. Since UPC-A is a subset of EAN-13 – UPC-A codes are EAN-13 codes that begin with a 0 – supplement support configured on ean_reader also works for UPC-A codes.
To enable supplement decoding:
Quagga.init({
decoder: {
readers: [{
format: "ean_reader",
config: {
supplements: [
'ean_5_reader', // 5-digit supplement
'ean_2_reader' // 2-digit supplement
]
}
}]
}
});
Supplement Result Structure
When a barcode with a supplement is decoded, the result includes a supplement property:
{
codeResult: {
code: "419871600890101", // Combined: main barcode + supplement
format: "ean_13", // Main barcode format
supplement: {
code: "01", // Supplement digits only
format: "ean_2" // "ean_2" or "ean_5"
}
}
}
The main codeResult.code contains the full combined value, while codeResult.supplement provides the supplement details separately.
Important Notes About Supplements
Supplement order matters: The reader stops when it finds the first matching supplement. List ean_5_reader before ean_2_reader if you want to prioritize 5-digit extensions.
Cannot read regular EAN-13 with supplements enabled: If you configure supplements, that reader instance can only decode EAN codes with supplements. To read both:
Quagga.init({
decoder: {
readers: [
"ean_reader", // Regular EAN-13 without supplements
{
format: "ean_reader",
config: {
supplements: ['ean_5_reader', 'ean_2_reader']
}
} // EAN-13 with supplements
]
}
});
This configuration creates two separate reader instances.
External Readers
Quagga2 supports external reader modules for additional barcode formats not built into the core library.
QR Code Reader
For QR code support, see quagga2-reader-qr.
External readers extend Quagga2’s capabilities beyond 1D barcodes:
import Quagga from '@ericblade/quagga2';
import QRReader from 'quagga2-reader-qr';
// Register external reader
Quagga.registerReader('qr', QRReader);
Quagga.init({
decoder: {
readers: ['qr'] // Use external QR reader
}
});
External Reader Priority
External readers follow the same priority rules as built-in readers. Once registered with Quagga.registerReader(), an external reader can be placed anywhere in the readers array, and its position determines when it attempts to decode relative to other readers:
// Register external reader first
Quagga.registerReader('my_custom_reader', MyCustomReader);
// Use in config - position determines priority
Quagga.init({
decoder: {
// External reader tried first, then built-in readers
readers: ['my_custom_reader', 'ean_reader', 'code_128_reader']
}
});
Key points:
- External readers must be registered via
registerReader()before use - Their position in
readersarray determines decode priority - There is no automatic “internal first, external second” ordering
- External readers interleave freely with built-in readers
Creating Custom Readers
You can create your own barcode reader implementations by extending the BarcodeReader prototype exported by Quagga2. See How-To: Create External Readers for details.
Reader Performance
Different readers have different performance characteristics:
Fastest readers:
code_128_reader- Optimized, widely usedean_reader- Fast and reliable
Slower readers:
code_39_reader- More complex patterni2of5_reader- Requires more validation
Resource intensive:
- Multiple readers enabled simultaneously
- Readers with supplements configured
Validation
Some barcode formats include check digits for validation:
- EAN-13/EAN-8: Built-in check digit
- Code 128: Built-in check digit
- UPC-A/UPC-E: Built-in check digit
For additional validation in your application, consider using barcode-validator.
Related
- Configuration Reference - Complete config options
- API Documentation - How to use Quagga2 methods
- Tips & Tricks - Handling false positives