Node.js

Barcode Generator API for Node.js

Generate barcodes in Node.js with the built-in fetch API - zero npm dependencies.

One GET request returns Code 128, EAN, UPC, GS1-128, DataMatrix or QR codes as SVG, PNG, PDF or EPS.

Works identically in Express handlers, Next.js route handlers, serverless functions and cron scripts.

The free tier includes 1,000 API calls per month; GS1 input is validated server-side.

Node barcode packages typically wrap native canvas builds or bundle font files, which is exactly the kind of dependency that breaks on Alpine images and serverless platforms. Calling a REST API avoids the native toolchain entirely: since Node 18, fetch is built in, so the examples below have zero dependencies.

SVG output is usually the best default for web work - it is small, sharp at any resolution and safe to inline. Switch the format parameter to png for raster needs or pdf/eps for print pipelines.

Setup

# Node 18+ - no install needed, fetch is built in

Generate barcodes in Node.js

const API_KEY = process.env.BARGEN_API_KEY; // create one at bargen.pro/dashboard
const BASE = "https://api.bargen.pro/v1";

async function generate(type, data, options = {}) {
  const params = new URLSearchParams({ data, format: "svg", ...options });
  const res = await fetch(`${BASE}/barcode/${type}?${params}`, {
    headers: { "X-API-Key": API_KEY },
  });
  if (!res.ok) throw new Error(`BarGen ${res.status}: ${await res.text()}`);
  return Buffer.from(await res.arrayBuffer());
}

// A Code 128 barcode as SVG
const svg = await generate("code128", "ORDER-2026-0042");
await import("node:fs/promises").then(fs => fs.writeFile("order.svg", svg));

// A GS1-128 barcode - Application Identifiers validated server-side
const gs1 = await generate("gs1-128", "(01)09501101530003(17)261231(10)AB123");

// A QR code as PNG with custom colour and scale
const png = await generate("qrcode", "https://bargen.pro", {
  format: "png", color: "1a1a2e", scale: "4",
});

Bulk generation with the batch endpoint

// Up to 50 barcodes in one request via the batch endpoint
const res = await fetch(`${BASE}/barcode/batch`, {
  method: "POST",
  headers: { "X-API-Key": API_KEY, "Content-Type": "application/json" },
  body: JSON.stringify({
    codes: [
      { type: "code128", data: "SKU-0001" },
      { type: "code128", data: "SKU-0002" },
      { type: "qrcode",  data: "https://example.com/p/1" },
    ],
    options: { format: "svg" },
  }),
});
const { results } = await res.json();
results.forEach(r => console.log(r.index, r.success));

Frequently asked questions

Does this work on Vercel, Netlify and AWS Lambda?

Yes - that is a major reason to use an API instead of a canvas-based npm package. There is no native binary to compile, so cold starts stay small and the same code runs on any Node 18+ runtime, including edge-adjacent serverless platforms.

How do I show a barcode in an Express or Next.js response?

Proxy the bytes with the right content type: res.type("image/svg+xml").send(svg) in Express, or return new Response(svg, { headers: { "Content-Type": "image/svg+xml" } }) in a Next.js route handler. Cache generated results if the same code is requested repeatedly.

Should I call the API from the browser?

No - that would expose your API key. Generate server-side (or at build time) and serve the image, or proxy the request through your backend where the key stays secret.

Is there a free tier?

Yes - 1,000 API calls per month free with no credit card, then $29/month for 10,000 calls and $79/month for 100,000 with a 99.9% SLA.

API basics

Endpoint
GET api.bargen.pro/v1/barcode/{type}
Auth
X-API-Key header
Output
SVG, PNG, PDF, EPS
Formats
25 barcode types incl. GS1 and postal
Free tier
1,000 calls/month
Full API reference

Code on GitHub

Runnable examples for every language live in the public docs repository.

bargen-pro/bargen-api-docs

Start generating barcodes from Node.js

Free tier with 1,000 API calls per month. No credit card required.