Aug 14, 2024
Boost Social Media Engagement with Dynamic OG Images Using Puppeteer
Learn how to boost social media engagement by dynamically generating custom Open Graph images using Puppeteer and an Express server for personalized user sharing.
Author


Book a call
Table of Contents
Creating dynamic Open Graph (OG) images and tags for your web applications can significantly enhance social sharing and user engagement. This tutorial will guide you through setting up an Express server that dynamically generates user-specific OG images using Puppeteer. We’ll use a custom HTML template, generate screenshots, and use these for social media previews.
What is an Open Graph (OG)?
Open Graph (OG) is a protocol that transforms web pages into rich, engaging content when shared on social media platforms. For example, when a link is shared on Facebook, OG tags dictate how it appears, including its title, description, and associated image. By tailoring these tags, you can make your shared links more appealing and interactive.
Prerequisites
- Node.js installed
- Puppeteer for Node.js
Step 1: Setting Up the Express Server
First, let’s create a new Express server.
Create a file named server.js and set up a basic Express server:
Step 2: Creating the Route Handler
Next, create a route that will handle the generation of the OG image. This route will generate an HTML template with dynamic data and use Puppeteer to take screenshots. In a real application, you might fetch user data from a database like SQL, Firebase, or MongoDB. For simplicity, we’ll hardcode the user data in this example.
Step 3: Generating HTML Template
Now, let’s create a function to generate an HTML template with dynamic user data. This template will be used to create the OG image.
Step 4: Capturing the OG Image with Puppeteer
We need a function to generate an OG image using Puppeteer. This function will render the HTML template and take a screenshot, saving it locally.
Step 5: Setting Up the Server Listener
Finally, we set up the server to listen on the specified port.
Usage
To use this setup, make a GET request to the /generate-og/:userId route, replacing :userId with the actual user ID you want to generate an OG image for. The server will generate a dynamic HTML template, capture an image with Puppeteer, and return an HTML response with the appropriate OG tags.
For example:
GET <http://localhost:3000/generate-og/12345>
This will generate an OG image for the user with ID 12345, save it locally, and return an HTML page with the OG tags ready for sharing.
Notes
- Dynamic Data: While this example hardcodes user data, in a real-world application, you would fetch this data from a database such as SQL, Firebase, or MongoDB.
- OG Tags: Open Graph tags are essential for ensuring your content is displayed correctly when shared on social media platforms.
Conclusion
By following these steps, you can dynamically generate OG images and tags tailored to individual users, enhancing the sharing experience and boosting engagement on social media platforms. This setup leverages the power of Puppeteer to create a seamless and efficient user experience.
Subscribe to Our Newsletter
Subscribe to RSS
Press & Media Hub RSS FeedRelated Articles.
More from the engineering frontline.
Dive deep into our research and insights on design, development, and the impact of various trends to businesses.

Jun 19, 2026
We Built a 114-Second AWS-to-Azure Failover. Here’s What We Learned
A practical guide to building a 114-second multi-cloud disaster recovery failover between AWS and Azure — what we built, what broke, and what we learned.

Jun 12, 2026
Cloud-Native and Cloud-Agnostic Are Not Ideologies; They Are Business-Stage Decisions
This blog explains how organizations can balance speed, scalability, and operational flexibility as they grow from startup to enterprise scale.

Jun 8, 2026
Geeklego: The Open-Source Design System Built to Work With AI
Build AI-generated UIs without design drift. Explore Geeklego’s open-source design system, token editor, and AI-powered workflow layer.

May 18, 2026
Your Vibe Code Has No Memory. DESIGN.md Fixes That.
A single Markdown file called DESIGN.md gives your AI agent the design memory it lacks — keeping your UI consistent across every session.

May 14, 2026
Building a Production-Ready Image Cropper in React Native
A practical guide to building a custom gesture-driven image cropper in React Native, with support for both profile and cover photo crops.

Apr 23, 2026
From Manual Testing to AI-Assisted Automation with Playwright Agents
This blog discusses the value of Playwright Agents in automating workflows. It provides a detailed description of setting up the system, as well as a breakdown of the Playwright Agent’s automation process.