← Back to blog
AI & Automation2 min read

QR codes in JavaScript and Node.js: npm package for images or service for dynamic codes?

Bild von Unsplash

Image libraries from npm

Anyone who needs a QR code in JavaScript or Node.js will find many libraries on npm. They generate an image or SVG from text, offline and without a service. This is ideal for fixed content such as ticket identifiers or payment data.

When you need more

Such an image is static. If you want the target to be changeable after printing, want to count scans, or want to know when a target fails, you need a service for dynamic codes. Same-QR stores the target behind a short, constant address, counts scans, and checks all targets every night.

The sameqr-CLI from npm

Same-QR has its own command-line program, without dependencies, from Node.js 18:

npm install -g sameqr
sameqr login
sameqr qr create --name "Flyer Herbst" --url https://example.com/herbst --json

"sameqr login" asks for your API key discreetly. You create the key in the dashboard under Account, "Access for CLI, scripts and agents". In scripts, you set SAMEQR_API_KEY instead. With --json, every command provides output that your script can read directly.

REST API from Node.js

For applications that continuously generate codes, you call the API directly. Since Node.js 18, the built-in fetch suffices:

const antwort = await fetch("https://sameqr.com/api/v1/qr", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SAMEQR_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ name: "Produkt 4711", targetUrl: "https://example.com/p/4711" }),
})
const daten = await antwort.json()
if (!antwort.ok) throw new Error(daten.error.message)
console.log(daten.id)

Important for web applications: The key must never end up in the browser. Requests to the API belong on your server.

Decision aid

  • Content never changes, no statistics needed: image library from npm.
  • One-time many codes: CSV import in the dashboard or a short script with the sameqr CLI.
  • Recurring processes in the terminal or with a coding agent: sameqr CLI with --json.
  • Codes are generated continuously in your application: REST API from the server.

Conclusion: why Same-QR

Same-QR fits into every JavaScript project: a dependency-free CLI from npm, a REST API for fetch, and an MCP server for coding agents, all in every plan. This way, you get dynamic codes with statistics without having to operate your own redirection service.

Get started right away: sign up for free at sameqr.com, two dynamic QR codes are free forever. API, CLI and MCP server are included in every plan, and the documentation is at sameqr.com/entwickler.

Create dynamic QR codes for free
Start with 2 dynamic QR codes that are free forever. No subscription, no credit card.
Start free now →

Frequently asked questions

Can I use the sameqr CLI in a Node.js project?

Yes. It runs on Node.js 18 and can be called from scripts. With --json, you get processable output.

Can I use the API key in the frontend?

No. Everything running in the browser can be read by any visitor. Requests with the key belong on the server.

Are codes from an npm library worse?

Not worse, only static. For fixed content, they are ideal; for printed codes with changing targets, they are not.

Reserve a spot

Reserve your spot before we go live.

One email as soon as the tool goes live — including pricing and the free plan. No spam, unsubscribe any time.

Only until launchLaunching in the next few weeks
  • Your free account is reserved — there is nothing to pay yet anyway
  • 90 days of unlimited destination changes instead of 30, only for early sign-ups
  • Launch price locked in, even if we raise prices later

By subscribing you consent to receiving the newsletter. You can withdraw consent at any time via the unsubscribe link in every email.

Keep reading