Getting Started
This guide will help you quickly set up notion-to-md v4 and convert your first Notion page to Markdown.
Installation
First, install the package using npm or yarn:
npm install notion-to-md@alpha
Prerequisites
Before you can convert Notion pages to Markdown, you need to:
- Set up a Notion integration in your workspace
- Get your integration token
- Share the page you want to convert with your integration
Basic Usage
Here’s a simple example demonstrating how to convert a Notion page to Markdown:
import { Client } from '@notionhq/client';
import { NotionToMarkdown } from 'notion-to-md';
import { DefaultExporter } from 'notion-to-md/plugins/exporter';
// Initialize the Notion client with your integration token
const notion = new Client({
auth: 'your-notion-integration-token',
});
async function convertPage() {
try {
// Replace with your actual page ID
const pageId = 'your-notion-page-id';
// use the default exporter
const exporter = new DefaultExporter({
outputType: 'file',
outputPath: `some/dir/${pageId}.md`
});
const n2m = new NotionConverter(notion)
.withExporter(exporter);
// Convert the page
await converter.convert(pageId);
console.log('✓ Successfully converted page to markdown!');
} catch (error) {
console.error('Conversion failed:', error);
}
}
convertPage();
The DefaultExporter supports three output types:
file
- Saves the markdown to a file:
new DefaultExporter({
outputType: 'file',
outputPath: 'some/dir/output.md'
})
stdout
- Prints the markdown to console:
new DefaultExporter({
outputType: 'stdout'
})
buffer
- Stores the markdown in a buffer object:
const buffer = {};
new DefaultExporter({
outputType: 'buffer',
buffer: buffer
})
// pageId="..."
// access output using buffer[pageId]
Tip
Learn how to create your own exporter plugins to save/publish conversion output to different destinations.
Next Steps
Once you have basic conversion working, you might want to explore more advanced features:
- Media Handling - Download and process images and files
- Page Reference Handling - Handle links between Notion pages
- Plugin system - Extend the functionality of notion-to-md
- Exporter Plugin - Save conversion output to different destinations
- Renderer Plugin - Create custom output formats
- Fetcher - Customize the fetching process
That’s it! You’ve successfully set up notion-to-md v4 and converted your first page.