---
title: "Node.js"
description: "Generate images with the Imejis.io API in Node.js using the built-in fetch, no dependencies. A tested example that POSTs dynamic field overrides and saves the rendered image."
url: "https://www.imejis.io/apis/javascript"
published: "2021-12-24"
---

# Node.js

## Node.js

Generate an image from a template with a single POST request, using the `fetch` built into Node.js 18 and later. No extra dependencies, and no webhook to wait on: the finished image comes back in the response.

Set two environment variables first: `IMEJIS_API_KEY` (from your dashboard) and `IMEJIS_DESIGN_ID` (any design's ID). Then send the fields you want to change as `component.property` pairs, for example `headline.text`.

```javascript showLineNumbers title="Node.js (fetch)"
import { writeFile } from "node:fs/promises"

const designId = process.env.IMEJIS_DESIGN_ID
const apiKey = process.env.IMEJIS_API_KEY

const response = await fetch(`https://render.imejis.io/v1/${designId}`, {
  method: "POST",
  headers: { "dma-api-key": apiKey, "Content-Type": "application/json" },
  body: JSON.stringify({ "headline.text": "Hello from Node.js" }),
})

const image = Buffer.from(await response.arrayBuffer())
await writeFile("output.jpg", image)
console.log("status", response.status, "bytes", image.length)
```

Save it as a `.mjs` file (or set `"type": "module"` in your `package.json`) and run it with `node file.mjs`.

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

The response is the raw image (`image/jpeg` by default). Save it to disk, stream it, or return it straight from your own endpoint.
