Orshot Logo
OrshotDocs

Node.js

Get started with Orshot Node SDK

Installation

npm install --save orshot

Import

import { Orshot } from "orshot";

Initialise

const orshot = new Orshot(<ORSHOT_API_KEY>);

Render from a template

const response = await orshot.renderFromTemplate({
  templateId,
  modifications,
  responseType: "base64",
  responseFormat: "png",
});

Generate a Signed URL

const response = await Orshot.generateSignedUrl({
  templateId,
  modifications,
  expiresAt: 1744276943,
  renderType: "images",
  responseFormat: "png",
});

Examples

base64 response format

import { Orshot } from "orshot";
const orshot = new Orshot("<ORSHOT_API_KEY>");
let templateId = "open-graph-image-1";
let modifications = {
  title: "Orshot",
  description: "Create Visuals and Automate Image Generation",
  textColor: "",
  backgroundImageUrl: "",
  backgroundColor: "",
};
const response = await orshot.renderFromTemplate({
  templateId,
  modifications,
  responseType: "base64",
  responseFormat: "png",
});

url response format

import { Orshot } from "orshot";
const orshot = new Orshot("<ORSHOT_API_KEY>");
let templateId = "open-graph-image-1";
let modifications = {
  title: "Orshot",
  description: "Create Visuals and Automate Image Generation",
  textColor: "",
  backgroundImageUrl: "",
  backgroundColor: "",
};
const response = await orshot.renderFromTemplate({
  templateId,
  modifications,
  responseType: "url",
  responseFormat: "png",
});

binary response format

import { Orshot } from "orshot";
import { createWriteStream } from "fs";
 
const orshot = new Orshot("<ORSHOT_API_KEY>");
 
let templateId = "open-graph-image-1";
let modifications = {
  title: "Orshot",
  description: "Create Visuals and Automate Image Generation",
  textColor: "",
  backgroundImageUrl: "",
  backgroundColor: "",
};
 
const response = await orshot.renderFromTemplate({
  templateId,
  modifications,
  responseType: "binary",
  responseFormat: "png",
});
const arrayBuffer = await response.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);
 
createWriteStream("og.png").write(buffer);

This example writes the binary image to the file og.png in the current directory.

renderFromTemplate

Use this function to render an image/pdf. Render template takes in 4 options passed as an object

{
  templateId,
  modifications,
  responseType,
  responseFormat
}
keyrequireddescription
templateIdYesID of the template (open-graph-image-1, tweet-image-1, beautify-screenshot-1, ...)
modificationsYesModifications for the selected template.
responseTypeNobase64, binary, url (Defaults to base64).
responseFormatNopng, webp, pdf, jpg, jpeg (Defaults to png).

For available templates and their modifications refer Orshot Templates Page

generateSignedUrl

Use this function to generate signed URLs

{
  templateId,
  modifications,
  renderType,
  responseFormat,
  expiresAt
}
keyrequireddescription
templateIdYesID of the template (open-graph-image-1, tweet-image-1, beautify-screenshot-1, ...)
modificationsYesModifications for the selected template.
expiresAtYesExpires at in unix timestamp (Number).
renderTypeNoimages, pdfs (Defaults to images).
responseFormatNopng, webp, pdf, jpg, jpeg (Defaults to png).

On this page