A rich API to your markdown files in seconds.

An open JS library to turn markdown files into structured, queryable data (SQL and JSON). Build rich markdown-powered sites fast and reliably.

Features

Key Advantages of MarkdownDB

Power of plain text:
Combination of unstructured content and structured data in simple Markdown files.
Simplicity at core:
Turn your Markdown files into a queryable, lightweight SQL database.
Flexible and extendable:
Bring your own document types, extend your frontmatter with computed fields and check for errors with custom validations.
Simple API:
Get a list of all or some Markdown files, filter them by frontmatter fields, and more.
Do one thing well:
MarkdownDB just gives you a database and an API — a super-powerful and extensible way to create those from markdown.
Open source:
Your content isn't locked away in proprietary platforms. It's open, it's free, it's yours.

Features

Key Features of MarkdownDB

Task extraction

Extract tasks from markdown files easily.

- [x] do laundry
{
  "metadata": {
    "tasks": [{ "description": "do laundry", "checked": true }]
  }
}

Frontmatter fields extraction

Extract structured markdown data from your markdown frontmatter.

---
title: Example Post
date: 2023-01-01
---

# Content
{
  "metadata": {
    "title": "Example Post",
    "date": "2023-01-01"
  }
}

Tags extraction

Extract tags from markdown body and from tags frontmatter field.

---
tags: frontmatter_tag_1, frontmatter_tag_2
---
# Some heading
#body_tag

Lorem ipsum #tag1 #tag2 #tag3
{
  "metadata": {
    "tags": ["frontmatter_tag_1", "frontmatter_tag_2"]
  },
  "tags": ["body_tag", "frontmatter_tag_1", "frontmatter_tag_2"]
}

Computed Fields

Compute additional metadata fields on the fly with custom functions.

const addTitle = (fileInfo, ast) => {
  const headerNode = ast.children.find((node) => node.type === "heading");
  const title = headerNode
    ? headerNode.children.map((child) => child.value).join("")
    : "";
  fileInfo.title = title;
};

client.indexFolder({
  folderPath: "PATH_TO_FOLDER",
  customConfig: { computedFields: [addTitle] },
});

Our vision

Your content, your database

Markdown files already contain structured data — frontmatter fields, tags, links, tasks. Most tools ignore it. MarkdownDB extracts it, indexes it, and makes it queryable, without touching your files or locking you into a platform.

Plain text in. Rich queryable data out.

Learn more about the Markdown Database Pattern →

Quickstart

Start using MarkdownDB in just a few steps

Step 1: You have a folder of markdown content

For example, your blog posts. Each file can have a YAML frontmatter header with metadata like title, date, tags, etc.

---
title: My first blog post
date: 2021-01-01
tags: [a, b, c]
author: John Doe
---

# My first blog post

This is my first blog post.
I'm using MarkdownDB to manage my blog posts.

Step 2: Index the files with MarkdownDB

Use the npm mddb package to index Markdown files into an SQLite database. This will create a markdown.db file in the current directory.

# npx mddb <path-to-folder-with-your-md-files>
npx mddb ./blog

Step 3: Query your files with SQL...

E.g. get all the files with tag a.

SELECT files.*
FROM files
INNER JOIN file_tags ON files._id = file_tags.file
WHERE file_tags.tag = 'a'

Step 4: ...or using MarkdownDB Node.js API

Use our Node API to query your data for your blog, wiki, docs, digital garden, or anything you want!

import { MarkdownDB } from "mddb";

const client = new MarkdownDB({
  client: "sqlite3",
  connection: { filename: "markdown.db" },
});

const mddb = await client.init();
const blogFiles = await mddb.getFiles({
  frontmatter: { draft: false },
});

Roadmap

What's new and what's coming

Apr 2023

MarkdownDB released!

First version of the package released under @flowershow/markdowndb with basic functionalities, like indexing files into an SQLite database, extracting frontmatter data and basic JS API.

May 2023

Version 0.1.0

We added support for extracting and querying forward links and backlinks.

Aug 2023

Version 0.2.0

We fixed some annoying bugs and renamed package from @flowershow/markdowndb to just mddb.

Oct 2023

Version 0.3.0

Support for querying files by frontmatter field values.

Nov 2023

Version 0.4.0

Add Tags Extraction from Markdown Content.

Nov 2023

Version 0.5.0

Add tasks extraction from files. e.g - [ ] task

Dec 2023

Version 0.6.0

Implement JSON output to disk.

Coming soon...

Version 1.0.0

Support for custom document types and computed fields.

Start using MarkdownDB today.

Check out our tutorial and learn the basics of using MarkdownDB in the command line and in the Node.js project.

Built with LogoFlowershow