Install
openclaw skills install notion-to-markdownConvert Notion pages and databases to markdown format using the official Notion API. Use when you need to: (1) Export a single Notion page to markdown, (2) Bulk export entire Notion databases, (3) Automate Notion content publishing, or (4) Integrate Notion content into documentation workflows. Requires Notion API token setup.
openclaw skills install notion-to-markdownConvert Notion pages and databases to clean, readable markdown using the official Notion API.
Required Credentials:
NOTION_API_KEY - Your personal Notion integration token (required)Security Best Practices:
.env files containing NOTION_API_KEY to version control@notionhq/client library and communicates exclusively with Notion's API. No data is sent elsewhere.Network Access:
https://api.notion.com (official Notion API)Check your Node version:
node --version # Should be v14.0.0 or higher
npm --version
See Notion API Setup for complete instructions:
notioneq_...)export NOTION_API_KEY="your_token"cd scripts
npm install
Single page:
NOTION_API_KEY=your_token node convert.js <page-id> > output.md
Database export:
NOTION_API_KEY=your_token node convert.js <database-id> --database ./exports
Extract a page and output to a file:
node scripts/convert.js a1b2c3d4e5f6g7h8 > my-page.md
The converter automatically:
Convert all pages in a Notion database:
node scripts/convert.js a1b2c3d4e5f6g7h8 --database ./notion-export
Creates individual markdown files for each page:
notion-export/
├── page-one.md
├── page-two.md
└── page-three.md
The converter preserves page properties:
const result = await convertPageToMarkdown(pageId);
console.log(result.title); // Page title from Notion
console.log(result.markdown); // Converted markdown content
console.log(result.pageId); // Original page ID
✅ Text, headings, and paragraphs ✅ Bold, italic, underline, strikethrough, code inline ✅ Links (internal and external) ✅ Lists (ordered and unordered) ✅ Code blocks with syntax highlighting ✅ Tables ✅ Quotes and callouts ✅ Images (as markdown image syntax) ✅ Dividers and separators ✅ Database properties as frontmatter
Option 1: Using .env file (Recommended)
Create a .env file in the scripts directory:
# scripts/.env
NOTION_API_KEY=ntn_your_api_key_here
Then run the converter normally:
node convert.js <page-id> > output.md
The script automatically loads environment variables from .env via the dotenv package.
Option 2: Export environment variable
Permanently set in your shell:
# ~/.bashrc, ~/.zshrc, or ~/.config/fish/config.fish
export NOTION_API_KEY="notioneq_..."
Option 3: Set for a single command
NOTION_API_KEY=your_token node convert.js <page-id>
Security Note: Add .env to .gitignore to prevent accidentally committing your API key:
echo ".env" >> .gitignore
Notion URL format:
https://www.notion.so/Workspace-Name/Page-Title-abc123def456?v=xyz
↑ Page ID
Copy the ID part (without hyphens in the URL).
Same as page URL - find the ID in the database's URL.
Make sure the environment variable is exported:
export NOTION_API_KEY="notioneq_..."
echo $NOTION_API_KEY # Verify it's set
a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6sleep 0.5 between conversionsModify scripts/convert.js to process markdown before saving:
let markdown = result.markdown;
// Add custom processing
markdown = markdown.replace(/\n{3,}/g, '\n\n'); // Clean up spacing
fs.writeFileSync('output.md', markdown);
Convert multiple pages in a loop:
for pageId in page1 page2 page3; do
node convert.js $pageId > "$pageId.md"
done
The markdown output is plain text and compatible with:
For advanced usage, see the notion-to-md documentation and Notion API reference.
NOTION_API_KEY secret.gitignore for .env files