Convert Notion Pages to Markdown

2 minute read

This post has been updated since November 2022 to reflect the changes Notion has gone through since then.

Here Are the Steps

  1. Go to the top left of you Notion.

  1. Click ‘Export’.

  1. Choose your export option and ensure that you have Markdown and CSV selected.

OUTDATED

Last Updated: 2022-11-12

This still works but is no longer the preferred method!

This is the GitHub repo I use for conversions: https://github.com/souvikinator/notion-to-md

One thing to note is that images will be unavailable after ~2-3 days using this method as the buckets Notion uses to store them will have expired. Currently there is no workaround but to either rerun this automatically or manually link your static images to your markdown file.

Prerequisites for this guide:

  1. You have Node.js installed and configured on your local computer.
  2. You have a code editor (I use Visual Studio Code).
  3. You have Notion.

Step 1: Install Notion to Markdown on your Computer

Since I’m kind of dumb when it comes to using repos I just cloned all of the repo onto my personal computer using Git.

1git clone https://github.com/souvikinator/notion-to-md.git

Step 2: Create the Notion to Markdown Integration

  1. Go to https://www.notion.so/my-integrations and create a new Integration.

  2. Name it how you would like, and associate it with your chosen Notion workspace.

  3. Set the Integration to Read content and not to request any user information for privacy.

    1. Press Submit to create the Integration.

Step 3: Add your Integration to your Notion Workspace

  1. Go to the top left of you Notion.

  2. Add connections > add your Integration.

Step 4: Convert Notion to Markdown

  1. Open the cloned repository in your code editor and navigate/create test.js.

  2. Copy your Integration token. The token would be found on the same page that you created your Integration on Step 2.

  3. Add your Integration token secret to box 1, then add your page’s hash to box 2.

     1// test.js
     2const { Client } = require("@notionhq/client");
     3const { NotionToMarkdown } = require("notion-to-md");
     4// or
     5// import {NotionToMarkdown} from "notion-to-md";
     6
     7const notion = new Client({
     8auth: "secret_.......", // internal integration token
     9});
    10
    11// passing notion client to the option
    12const n2m = new NotionToMarkdown({ notionClient: notion });
    13
    14(async () => {
    15const mdblocks = await n2m.pageToMarkdown("cba61......"); // page's hash
    16const mdString = n2m.toMarkdownString(mdblocks);
    17
    18// writing to file
    19const fs = require('fs');
    20fs.writeFile("notion-to-markdown-output.md", mdString, (err) => {
    21	console.log(err);
    22});
    23})();
    
  4. Run the code:

    1node test.js
    

That’s it! Now you can put the Notion content wherever! 🥳