Skip to content

apiverve/social-card-generator-node-tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Social Card Generator | APIVerve API Tutorial

License: MIT Build Node.js Express APIVerve | HTML to Image

A Node.js web app for generating social media cards (Open Graph images). Design cards with custom colors, text, and templates, then export as PNG.

Screenshot


Get Your Free API Key

This tutorial requires an APIVerve API key. Sign up free - no credit card required.


Features

  • Visual card editor with live preview
  • Custom title, description, and author
  • Color picker for background and text
  • Pre-built templates (Blog, Product, Event)
  • Standard OG image size (1200x630)
  • Download as PNG
  • Built with Express.js

Quick Start

  1. Clone this repository

    git clone https://github.com/apiverve/social-card-generator-node-tutorial.git
    cd social-card-generator-node-tutorial
  2. Install dependencies

    npm install
  3. Add your API key

    Set environment variable or edit server.js:

    export API_KEY=your-api-key-here
  4. Start the server

    npm start
  5. Open in browser

    Visit http://localhost:3000 and create social cards!

Project Structure

social-card-generator-node-tutorial/
├── server.js           # Express server & API endpoint
├── public/
│   └── index.html      # Frontend editor UI
├── package.json        # Dependencies
├── screenshot.jpg      # Preview image
├── LICENSE             # MIT license
├── .gitignore          # Git ignore rules
└── README.md           # This file

How It Works

  1. User designs card in visual editor
  2. Editor generates HTML with styles
  3. Frontend sends HTML to /api/generate
  4. Server calls HTML to Image API
  5. API renders HTML and returns image URL
  6. User downloads the generated PNG

The API Call

const response = await fetch('https://api.apiverve.com/v1/htmltoimage', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x-api-key': API_KEY
  },
  body: JSON.stringify({
    html: '<html>...</html>',
    width: 1200,
    height: 630,
    format: 'png'
  })
});

API Reference

Endpoint: POST https://api.apiverve.com/v1/htmltoimage

Request Body:

Parameter Type Required Description
html string Yes HTML code to render
width number No Image width (default: 1280)
height number No Image height (default: 800)
format string No Output format: png, jpeg, webp

Example Response:

{
  "status": "ok",
  "error": null,
  "data": {
    "imageName": "79c8416d-8096-4524-adea-a948eb69a21e.png",
    "format": ".png",
    "downloadURL": "https://storage.googleapis.com/apiverve/...",
    "expires": 1766010253596,
    "htmlLength": 197,
    "dimensions": {
      "width": 800,
      "height": 600
    }
  }
}

Social Card Sizes

Platform Size
Open Graph (Facebook, LinkedIn) 1200 x 630
Twitter Card 1200 x 600
Pinterest 1000 x 1500

Use Cases

  • Blog posts - Generate OG images for articles
  • Product launches - Create announcement cards
  • Events - Design event share images
  • Marketing - Build campaign visuals
  • Documentation - Generate doc previews
  • Email headers - Create email banner images

Customization Ideas

  • Add image/logo upload
  • Save templates to database
  • Add more card layouts
  • Support custom fonts
  • Add icon library
  • Batch generation for multiple posts

Related APIs

Explore more APIs at APIVerve:

Free Plan Note

This tutorial works with the free APIVerve plan. Some APIs may have:

  • Locked fields: Premium response fields return null on free plans
  • Ignored parameters: Some optional parameters require a paid plan

The API response includes a premium object when limitations apply. Upgrade anytime to unlock all features.

License

MIT - see LICENSE

Links

Releases

No releases published

Packages

 
 
 

Contributors