Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →If a QR API accepts a JSON request but returns a PNG, response.json() will fail: the response body contains image bytes, not JSON. Check the HTTP status, read a successful PNG response with arrayBuffer(), and convert it to a Node.js Buffer. Request and response formats are separate parts of an API contract.
Why does response.json() fail when a QR API returns a PNG?
The request header Content-Type: application/json describes the body your code sends. It does not determine the format the server sends back. A QR endpoint can accept JSON describing the text and desired format, then return binary PNG bytes on success and JSON only when reporting an error. LinkScan documents that kind of contract: JSON input, PNG or SVG success output, and JSON error responses for 4xx and 5xx results. LinkScan API documentation.
Calling response.json() on PNG bytes asks JavaScript to parse image data as JSON, which produces a parsing error. Read the successful response according to the selected output format instead. QRGen documents PNG, SVG, and a JSON mode containing a modules matrix and size value; that JSON is structured QR data, not a PNG file. QRGen Node.js guide.
How to read a PNG response in Node.js
For Node.js 18 and later, native fetch is available. The following pattern checks for failure before reading the successful PNG body as bytes:
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
import { writeFile } from "node:fs/promises";
const response = await fetch(apiUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ data: "https://example.com", format: "png" }),
});
if (!response.ok) {
// Use this only when the API documents JSON error responses.
const error = await response.json();
throw new Error(error.error ?? `QR API failed: ${response.status}`);
}
const png = Buffer.from(await response.arrayBuffer());
await writeFile("qr.png", png);
The JSON error parsing in this example is appropriate only if the provider documents JSON errors. APIs differ; if the endpoint uses another error format, handle that contract instead. Checking response.ok first prevents a documented JSON error from being saved or forwarded as though it were an image. The PNG success path follows the byte-reading pattern in the QRGen Node.js guide.
How to relay the PNG through an Express route
Keep the image as a buffer when sending it to a browser or another client. Set the outgoing media type to image/png so the receiver interprets the body as an image; do not JSON-serialize the buffer.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
app.get("/qr.png", async (req, res, next) => {
try {
const response = await fetch(apiUrl, requestOptions);
if (!response.ok) {
return res.status(response.status).send("QR generation failed");
}
const png = Buffer.from(await response.arrayBuffer());
res.type("image/png").send(png);
} catch (error) {
next(error);
}
});
Choose caching behavior for the specific QR payload and endpoint rather than copying a universal cache duration: whether an image is safe and useful to cache depends on whether its contents are public and stable. QRGen documents Express forwarding with an image media type in its Node.js guide.
Choose a response reader for the output format
| API output | Read it with | What you receive | Typical use |
|---|---|---|---|
| PNG | arrayBuffer(), then Buffer.from() |
Binary raster image | Fixed-size image output or a system that expects PNG |
| SVG | text() |
Text markup | Scalable output, including print workflows where the receiving application accepts SVG |
| JSON | json() |
Structured data, if the provider explicitly offers a JSON response mode | Applications that need the QR matrix or other documented structured fields rather than an image file |
QRGen documents these PNG, SVG, and JSON options, while UseQR describes SVG as suitable for resizing and print use. Confirm the provider’s output contract and the receiving application’s requirements before choosing a format. QRGen Node.js guide; UseQR Node.js guide.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Hosted QR API or local Node.js generation?
A hosted API can provide generation without adding and maintaining a rendering dependency in your application, and may offer features your local implementation would otherwise need to build. Local generation with the qrcode package avoids sending the payload to a remote API and can work without network access. UseQR documents local PNG file output, data URLs, SVG strings, and streaming PNG to an HTTP response. These are implementation tradeoffs, not evidence of a performance advantage for either option. UseQR Node.js guide.
Consider where QR content goes before choosing a hosted service. A code may encode Wi-Fi credentials, personal contact information, payment details, or other sensitive data. UseQR recommends local generation for sensitive payloads; that is vendor guidance, not an independent security audit. For a hosted API, review its data handling and retention terms rather than assuming the payload is private.
Quick Recap
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Common QR API response errors and fixes
- JSON parse error on a successful response: The endpoint may have returned PNG bytes. Use
arrayBuffer()and convert the result to aBuffer. - Broken image after forwarding: Keep the response body binary and send it with the outgoing
Content-Type: image/png. - SVG treated as an image buffer: Read SVG output with
text()and return it with the SVG media type. - Error body handled as an image: Check
response.okbefore taking the success path, and parse failures according to the provider’s documented error format. - Assuming another provider behaves the same: Check its current endpoint, authentication, supported formats, limits, and error contract. For example, LinkScan documents bearer authentication and a limit of 60 requests per minute for its API; QRGen’s guide describes its example API as requiring no API key. Those details are provider-specific, not general QR API rules. LinkScan API documentation; QRGen Node.js guide.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

