Node.js Example

Using our MightyShare NPM package you can quickly generate social share images for your content.

If you are unfamiliar with template values you can look at our template detail pages for more information how to customize a template. Typically templates allow you to customize color (with hex color), text, and an image but some offer more customization.


Example code to use MightyShare in Node.js

Here’s an example using node.js to generate an open graph image. Once you have a URL generated you can use it in your og:image tag or display it anywhere on your site/application.

import MightyShare from 'mightyshare';

// API key from MightyShare.io
const mightyshare = MightyShare(API_KEY);

const options = {
  height: 630,
  width: 1200,
  template: 'standard-1',
  template_values: [
    {
      "name": "primary_color",
      "color": "#C18651"
    },
    {
      "name": "title",
      "text": "8 Stunning Beaches to Visit this Summer"
    },
    {
      "name": "background",
      "image_url": "https://images.unsplash.com/photo-1652953552047-d8fe57042a3a?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=80&raw_url=true&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1800"
    },
    {
      "name": "logo",
      "image_url": "https://mightyshare.io/wp-content/uploads/2022/05/your-logo-mightyshare-1.png"
    }
  ]
}

const imageUrl = mightyshare.generateUrl(options);
console.log(imageUrl);
Was this article helpful?

Related Articles