Barcode generator template

  • Node.js
  • Express

Make Code 128 and Code 39 barcode images for products, shelves and shipping labels.

A Node.js and Express app that makes barcode images. Enter a SKU, order number or any text, pick Code 128 or Code 39, choose whether to print the value underneath, and download the barcode as a PNG. Use it to print labels by hand, or call the route to add barcodes to packing slips.

The barcode generator app running

What it does

Code 128 and Code 39
The two formats most scanners and label printers read, for letters and numbers.
Ready to print
Returns a PNG with the value printed under the bars, or without it if you prefer.
Keeps your key private
The page calls your own server, which holds the key and limits each visitor to 10 barcodes a minute.

How it works

The route that makes a barcode.

server.js
const TYPES = ['code128', 'code39'];

// POST /api/generate { data, type, displayValue }
app.post('/api/generate', async (req, res) => {
  const data = str(req.body.data, 80);
  const type = TYPES.includes(req.body.type) ? req.body.type : 'code128';
  const displayValue = req.body.displayValue !== false;
  if (!data) return res.status(400).json({ error: 'Enter the text to encode.' });

  try {
    const result = await callApi('barcodegenerator', { body: { data, type, displayValue } });
    res.json({ success: true, data, type, imageUrl: result.downloadURL });
  } catch (err) {
    res.status(err.status || 502).json({ error: err.message });
  }
});

See the whole file on GitHub

Deploy it

  1. Get a free API key

    The free plan includes 200 credits a month, no card needed. Create your key.

  2. Deploy it

    Click Deploy to Vercel. Vercel copies the repo to your GitHub account and asks for APIVERVE_API_KEY: paste your key there.

  3. Open your app

    Vercel builds it and gives you a live URL, usually in about a minute. Every push to the repo redeploys it.

Try the Barcode Generator API — the call this template makes

Request
POSTapi.apiverve.com/v1/barcodegenerator
Body
Verification
Format

No key required to try it. Get a key to use it in your app.

Build your own with Barcode Generator. Start with 200 free credits. One key unlocks all 300+ APIs.

Explore the catalog

300+ APIs on the same key and the same response shape.

Browse all APIs