Developers

Make QR codes in Node.js

In Node.js 18 or later, build the URL with URLSearchParams and call fetch on https://qrcodesforever.com/qr.png or /qr.svg. Write the response to a file, or pass it on to your own users. Node's built-in fetch is all you need, the API takes no key, and the same URL always returns the same image.

Save a PNG

// save-qr.mjs
import { writeFile } from "node:fs/promises"

const params = new URLSearchParams({ url: "https://example.com/menu?table=4", size: "1024" })
const res = await fetch(`https://qrcodesforever.com/qr.png?${params}`)
if (!res.ok) throw new Error(`QR failed: ${res.status} ${await res.text()}`)
await writeFile("menu-qr.png", Buffer.from(await res.arrayBuffer()))

Run it with node save-qr.mjs. The .mjs extension is what makes top-level await work; in a .js file, set "type": "module" in package.json. You get a 1024-pixel PNG whose code opens https://example.com/menu?table=4. URLSearchParams encoded the inner ? and =, which is the whole reason to use it instead of string concatenation.

For SVG, call /qr.svg and write await res.text(). size only applies to PNG.

What a failure looks like

Change the url to notalink and the script throws:

Error: QR failed: 400 Missing or invalid content. Try ?url=example.com, ?upi=name@bank or ?type=wifi&ssid=MyWifi

The API validates before it draws. A link needs a real domain, a Wi-Fi code needs a network name, a contact card needs a name or company, and IBANs, Pix keys and Bitcoin addresses must pass their checksums. Data too long for one QR code gets a 413 with Too much data for one QR code. Errors are cached for five minutes, successes for a year.

Batch a list

import { writeFile } from "node:fs/promises"

const links = [
  { name: "menu", url: "https://example.com/menu" },
  { name: "reviews", url: "https://example.com/reviews" },
]

for (const { name, url } of links) {
  const res = await fetch(`https://qrcodesforever.com/qr.svg?${new URLSearchParams({ url })}`)
  if (!res.ok) { console.error(name, res.status, await res.text()); continue }
  await writeFile(`${name}.svg`, await res.text())
}

The loop runs one request at a time on purpose. There's no published rate limit, and sequential batches are how it stays that way. For a list without code, the bulk generator takes a CSV.

Other kinds take other fields. This object makes a calendar event:

{ type: "event", title: "Launch party", start: "2027-03-14T18:00", end: "2027-03-14T21:00", tz: "Europe/Berlin" }

The code holds a VEVENT with DTSTART:20270314T170000Z and DTEND:20270314T200000Z: the Berlin times converted to UTC, so every phone shows the right local time. All kinds are in the embed reference.

Passing images through Express

Usually the browser should load our URL directly from your HTML. Proxy only when the content shouldn't appear in your page source, like a ticket link:

import express from "express"

const app = express()

app.get("/ticket/:id/qr.png", async (req, res) => {
  const params = new URLSearchParams({ url: `https://example.com/ticket/${req.params.id}` })
  const r = await fetch(`https://qrcodesforever.com/qr.png?${params}`)
  if (!r.ok) return res.status(r.status).send(await r.text())
  res.type("png").set("Cache-Control", "public, max-age=31536000, immutable")
  res.send(Buffer.from(await r.arrayBuffer()))
})

app.listen(3000)

The ticket link still reaches our server inside the request; it just stays out of your HTML.

When to use the qrcode package instead

Our server draws codes with the qrcode package. What the API adds on top is the payload formats (Wi-Fi escaping, vCard, EPC, Pix with its CRC) and the rounded and dotted styles. If your codes hold plain links and you need to work offline, or the content is private enough that it shouldn't cross the network, install qrcode and skip us. Python users can do the same with the Python guide.

Written by Last updated