Why Use an API?
Most Node.js QR code libraries pull in native dependencies or Canvas bindings that break across platforms and Node versions. The QR Gen API gives you QR codes with a single fetch() call — no npm install, no native compilation, no Dockerfile changes. It works on Node 18+, Deno, Bun, Cloudflare Workers, and any runtime with fetch.
Quick Start
Node 18+ has native fetch. No packages needed:
import { writeFile } from "fs/promises";
const res = await fetch("https://qrgenapp.com/api/qr?data=https://example.com&format=png&size=512");
if (!res.ok) {
const err = await res.json();
throw new Error(err.error);
}
const buffer = Buffer.from(await res.arrayBuffer());
await writeFile("qr.png", buffer);
console.log("Saved qr.png");POST with JSON Body
For complex data like WiFi strings or vCards, POST avoids URL encoding headaches:
import { writeFile } from "fs/promises";
const res = await fetch("https://qrgenapp.com/api/qr", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
data: "WIFI:T:WPA;S:OfficeNetwork;P:securepass123;;",
format: "png",
size: 1024,
color: "1e293b",
ec: "H"
})
});
if (!res.ok) throw new Error((await res.json()).error);
await writeFile("wifi.png", Buffer.from(await res.arrayBuffer()));
Express.js Middleware
Serve dynamic QR codes from your Express app:
import express from "express";
const app = express();
app.get("/qr", async (req, res) => {
const { url, size = 256 } = req.query;
if (!url) return res.status(400).json({ error: "url param required" });
const qrRes = await fetch(
`https://qrgenapp.com/api/qr?data=${encodeURIComponent(url)}&size=${size}&format=png`
);
if (!qrRes.ok) return res.status(502).json({ error: "QR generation failed" });
res.set("Content-Type", "image/png");
res.set("Cache-Control", "public, max-age=86400");
const buffer = Buffer.from(await qrRes.arrayBuffer());
res.send(buffer);
});
app.listen(3000);
SVG Output
SVG is ideal for web embedding — resolution-independent and small:
const res = await fetch("https://qrgenapp.com/api/qr", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
data: "https://example.com",
format: "svg",
color: "0f172a",
bg: "f1f5f9"
})
});
const svg = await res.text();
// Embed in HTML
const html = `<div class="qr-container">${svg}</div>`;
Batch Generation
import { writeFile } from "fs/promises";
const urls = [
"https://example.com/product/1",
"https://example.com/product/2",
"https://example.com/product/3",
];
const results = await Promise.all(
urls.map(async (url, i) => {
const res = await fetch(
`https://qrgenapp.com/api/qr?data=${encodeURIComponent(url)}&format=png&size=512&ec=H`
);
if (!res.ok) throw new Error(`Failed for ${url}`);
const buffer = Buffer.from(await res.arrayBuffer());
const filename = `qr_${i + 1}.png`;
await writeFile(filename, buffer);
return filename;
})
);
console.log("Generated:", results);
JSON Format for Custom Rendering
const res = await fetch("https://qrgenapp.com/api/qr?data=hello&format=json");
const { modules, size } = await res.json();
// Render in terminal
for (const row of modules) {
console.log(row.map(cell => cell ? "██" : " ").join(""));
}
// Or use with Canvas, React, Three.js, etc.
console.log(`QR size: ${size}x${size} modules`);
TypeScript Types
interface QRRequest {
data: string;
format?: "png" | "svg" | "json";
size?: number; // 32-2048
color?: string; // hex without #
bg?: string; // hex without #
ec?: "L" | "M" | "Q" | "H";
margin?: number; // 0-10
}
interface QRJsonResponse {
modules: number[][];
size: number;
}
async function generateQR(options: QRRequest): Promise<Buffer> {
const res = await fetch("https://qrgenapp.com/api/qr", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(options)
});
if (!res.ok) {
const err = await res.json();
throw new Error(err.error);
}
return Buffer.from(await res.arrayBuffer());
}
Error Handling
try {
const res = await fetch("https://qrgenapp.com/api/qr?data=test&format=png");
if (!res.ok) {
const { error } = await res.json();
console.error(`API error (${res.status}): ${error}`);
return;
}
const buffer = Buffer.from(await res.arrayBuffer());
// use buffer...
} catch (err) {
console.error("Network error:", err.message);
}
See the full API Reference for all parameters and response formats.