Skip to content

Quickstart

Website screenshots in Node.js

Use fetch to create a screenshot with one HTTPS request and no browser infrastructure to manage.

Ironfang Render uses a standard HTTPS API, so Node.js can call it with fetch and does not require an SDK. A successful request returns the image bytes directly, ready to write to a file.

Get a key

Create an API key in the portal. The secret is displayed once and stored as a hash. Keep it in an environment variable named IRONFANG_API_KEY rather than in the source file; the example below reads it from there.

export IRONFANG_API_KEY="if_live_..."

Take a screenshot

import { writeFile } from 'node:fs/promises';

const key = process.env.IRONFANG_API_KEY;
if (!key) throw new Error('Set IRONFANG_API_KEY to your Ironfang API key.');

const resp = await fetch('https://api.ironfang.com/render/v1/screenshot', {
    method: 'POST',
    headers: {
        Authorization: `Bearer ${key}`,
        'Content-Type': 'application/json',
    },
    body: JSON.stringify({ url: 'https://example.com', width: 1280 }),
});

if (!resp.ok) {
    const { error } = await resp.json();
    throw new Error(`${resp.status} ${error.code}: ${error.message}`);
}

await writeFile('shot.png', Buffer.from(await resp.arrayBuffer()));

Run it, and the screenshot is saved as shot.png in the current directory:

node shot.mjs

Handling errors

Successful render responses are binary. Errors use JSON in the form {"error": {"code", "message"}}. A missing or unrecognised key returns 401 invalid_api_key. A key without the render:render scope returns 403 insufficient_scope.

// fetch does not throw for 4xx or 5xx responses. Check resp.ok
// before writing the response body to an image file.

PDFs and templates

The same call shape works for PDFs at /render/v1/pdf, and for templated images at /render/v1/image/{id}. Only the path and the body change.

Next