T03: Installing and Setting Up Mermaid

3.1 Installation Philosophy

Mermaid is not a standalone desktop application. It is a JavaScript-based rendering engine that can be:

  • Embedded in web pages

  • Used inside Markdown environments

  • Rendered via CLI

  • Integrated into documentation pipelines

Before installing, understand your usage model:

Use Case
Recommended Setup

Quick Markdown usage

GitHub / GitLab native support

Local development

VS Code extension

Static site documentation

Mermaid via npm

CI/CD rendering

Mermaid CLI

Web app integration

Mermaid JS library

We will cover all major setups.


3.2 Method 1 — Using Mermaid in GitHub (Zero Installation)

GitHub supports Mermaid natively inside Markdown.

Example

Steps:

  1. Create a .md file.

  2. Add the Mermaid code block.

  3. Push to GitHub.

  4. GitHub renders it automatically.

No installation required.

Best for:

  • README diagrams

  • Architecture docs

  • Open-source projects


3.3 Method 2 — Installing Mermaid via npm (Local Setup)

If you want full control locally, install Mermaid via Node.js.

Step 1: Install Node.js

Verify installation:

If not installed, download from: https://nodejs.orgarrow-up-right


Step 2: Initialize a Project


Step 3: Install Mermaid

This installs the Mermaid JavaScript library into node_modules.


3.4 Using Mermaid in an HTML Page

Create a file:

Add the following content:

Open in browser.

Mermaid will render automatically.


3.5 Method 3 — Installing Mermaid CLI (Professional Setup)

Mermaid CLI allows rendering diagrams into SVG/PNG from terminal.

This is critical for:

  • CI/CD

  • Automated documentation

  • Static exports


Step 1: Install CLI Globally

Verify installation:


Step 2: Create a Mermaid File

Create:

Add:


Step 3: Render to SVG

Output:

  • architecture.svg

You now have a production-ready diagram.


3.6 Rendering to PNG


3.7 Using Mermaid in VS Code

Install extension:

  • Search: “Mermaid Markdown Preview”

  • Install extension

  • Open .md file

  • Use Preview mode

Example Markdown:

Preview renders live.


3.8 Setting Default Configuration

Mermaid supports configuration options.

Example:

Themes available:

  • default

  • dark

  • forest

  • neutral


3.9 CLI Configuration File

You can create a config file:

Example:

Use it:


3.10 Production Integration Example

Suppose your documentation build pipeline runs:

You can add this to:

  • GitHub Actions

  • GitLab CI

  • Jenkins

  • Azure DevOps

Example GitHub Action step:

Now diagrams regenerate automatically on every commit.


3.11 Troubleshooting Common Issues

1. “mmdc: command not found”

Fix:

2. Node Version Too Old

Upgrade Node:

Mermaid requires modern Node versions.

3. Browser Module Errors

Ensure:

is included in <script> tag.


3.12 Hands-On Lab

Exercise 1

  1. Install Mermaid CLI.

  2. Create flow.mmd.

  3. Add:

  1. Render to SVG.

  2. Change direction to TD.

  3. Re-render.

Observe how code change affects output.


3.13 Choosing the Right Setup

Scenario
Recommended Method

README diagrams

GitHub native

Developer workflow

VS Code

Documentation site

npm library

CI rendering

Mermaid CLI

Web product

JS integration


3.14 Key Takeaway

Mermaid installation is flexible because it is:

  • JavaScript-based

  • Platform-agnostic

  • Automation-ready

  • CI/CD compatible

You do not “install a tool” in the traditional sense.

You integrate a rendering engine into your workflow.

In the next chapter, we will dive into Flowcharts, the most commonly used Mermaid diagram type, and explore their syntax in depth.

Last updated