---
title: "Express"
description: "Generate dynamic OG images and on-demand graphics in Express with the Imejis.io API. A secure proxy route that keeps your API key server-side and returns a cached image."
url: "https://www.imejis.io/apis/express"
published: "2026-07-27"
---

# Express

## Express

Generate a unique OG image for every page, or any on-demand graphic, from a single Imejis template. The pattern below uses an Express route as a thin proxy: your API key stays on the server, and the browser (and social crawlers) only ever see your own URL.

Set two environment variables first: `IMEJIS_API_KEY` (from your dashboard) and `IMEJIS_DESIGN_ID` (any design's ID).

```bash title=".env"
IMEJIS_API_KEY=your_api_key
IMEJIS_DESIGN_ID=your_design_id
```

### 1. A route that renders the image

This route takes a `title` query param, POSTs it to Imejis as a `component.property` override, and streams the finished image back. Because the key is sent server-side, it never reaches the client. Node.js 18+ has a global `fetch`; on older versions install `node-fetch` and import it here.

```javascript showLineNumbers title="server.js"
import express from "express"

const app = express()

app.get("/og", async (req, res) => {
  const title = req.query.title ?? "Untitled"

  const upstream = await fetch(
    `https://render.imejis.io/v1/${process.env.IMEJIS_DESIGN_ID}`,
    {
      method: "POST",
      headers: {
        "dma-api-key": process.env.IMEJIS_API_KEY,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({ "headline.text": title }),
    }
  )

  const image = Buffer.from(await upstream.arrayBuffer())

  res.set({
    "Content-Type": "image/jpeg",
    // Renders are deterministic, so cache aggressively at the edge/CDN.
    "Cache-Control": "public, immutable, no-transform, max-age=31536000",
  })
  res.send(image)
})

app.listen(3000)
```

### 2. Point your metadata at it

Reference the route from whatever renders your page's `<head>`, passing each page's real data. Social platforms fetch `/og?title=…` from your own domain, no key exposed.

```html showLineNumbers title="head.html"
<meta
  property="og:image"
  content="https://your-site.com/og?title=Hello%20from%20Express"
/>
<meta name="twitter:card" content="summary_large_image" />
```

**Override any field.** Each dynamic component exposes keys like `headline.text`, `title.color`, or `image.image`. Send only the ones you want to change. A design's overridable fields are listed in its Share / API panel.
