Railway

Deploy Mermaid API

Render Mermaid diagrams as PNG/SVG via HTTP API

Deploy Mermaid API

Just deployed

Mermaid API

Render Mermaid diagram code to PNG or SVG images via a simple HTTP API. Designed for one-click deployment on Railway.

Deploy to Railway

Features

  • POST /render — Render diagrams from JSON body { code, format, theme, scale }
  • GET /render — Render diagrams from query string ?code=...&format=...
  • PNG or SVG output — Choose between raster or vector output
  • Multiple themesdefault, dark, forest, neutral
  • Concurrent rendering — Browser pool with configurable concurrency
  • Health checkGET /health for Railway health monitoring
  • Input sanitization — HTML-escaped Mermaid code before rendering

Deploy and Host

Click the Deploy to Railway button above to launch the Mermaid API service in minutes. Chromium and Puppeteer are pre-installed in the container — no additional configuration needed.

About Hosting

This template runs a Node.js Express server with Puppeteer for headless Chromium rendering on Railway. A browser pool manages concurrent diagram rendering with automatic browser reuse and resource cleanup.

Why Deploy

  • Self-host a diagram-as-code API without external service dependencies
  • No rate limits or API keys — full control over your rendering pipeline
  • Eliminate cloud diagram service costs with your own single-container deployment
  • Scale horizontally by increasing MAX_CONCURRENT for higher throughput

Common Use Cases

  • CI/CD pipeline — auto-generate architecture diagrams from Markdown
  • Documentation sites — embed live-updating Mermaid diagrams
  • API gateway backend — render diagrams on demand for web/mobile apps
  • Notification and reporting — auto-generated diagram attachments

Dependencies for

  • Node.js 20 — JavaScript runtime
  • Chromium 120+ — Headless browser for SVG-to-PNG rendering
  • Puppeteer 23 — Browser automation and screenshot API

Deployment Dependencies

DependencyDescription
Railway accountMust have access to 1+ service
No database neededFully self-contained — no companion services required

Environment Variables

VariableDefaultDescription
PORT8080HTTP server port
NODE_ENVproductionNode.js environment
CHROMIUM_PATH/usr/bin/chromiumPath to Chromium binary
MAX_CONCURRENT4Max concurrent browser instances

API Usage

POST /render

POST /render
Content-Type: application/json

{
  "code": "graph TD;\\nA-->B;\\nA-->C;\\nB-->D;\\nC-->D;",
  "format": "png",
  "theme": "default",
  "scale": 2
}

Returns the rendered diagram as PNG or SVG binary.

GET /render

GET /render?code=graph%20TD%3B%0AA--%3EB%3B&format=svg&theme=dark

Returns the rendered diagram as PNG or SVG binary.

Supported Diagram Types

All Mermaid diagram types are supported:

  • Flowcharts (graph TD, graph LR, etc.)
  • Sequence diagrams (sequenceDiagram)
  • Class diagrams (classDiagram)
  • State diagrams (stateDiagram-v2)
  • Gantt charts (gantt)
  • Pie charts (pie)
  • ER diagrams (erDiagram)
  • Git graphs (gitGraph)
  • User journey diagrams (journey)
  • Requirement diagrams (requirementDiagram)
  • C4 diagrams (C4Context, etc.)
  • Timeline diagrams (timeline)
  • Mind maps (mindmap)
  • And more...

Themes

ThemeDescription
defaultLight theme (default)
darkDark theme
forestGreen-toned theme
neutralNeutral gray theme

FAQ

Q: Why does the first request take several seconds? A: Puppeteer needs to launch a Chromium instance on the first request. Subsequent requests reuse the browser pool.

Q: What is the maximum input size? A: 50,000 characters of Mermaid code. Larger inputs return a 400 error.

Q: Can I use this for production workloads? A: Yes — the service includes a managed browser pool, input validation, and proper error handling. Scale MAX_CONCURRENT for higher throughput.

License

MIT


Template Content

More templates in this category

View Template
N8N Main + Worker
Deploy and Host N8N with Inactive worker.

jakemerson
120
View Template
Evolution API with n8n
[Jul'26] WhatsApp automation platform using Evolution API, n8n & PostgreSQL

codestorm
56
View Template
Postgres Backup
Cron-based PostgreSQL backup to bucket storage

Railway Templates
868