npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@onebeyond/notion-exporter

v0.6.0

Published

:warning: **This is a fork maintained by One Beyond.**. The fork started with the commit [`712b4a9`](https://github.com/yannbolliger/notion-exporter/commit/712b4a92882dcaef44e5625e258da4010a027155) from the original repository. The original repository is

Downloads

9

Readme

Notion Exporter 🛫

:warning: This is a fork maintained by One Beyond.. The fork started with the commit 712b4a9 from the original repository. The original repository is located at yannbolliger/notion-exporter

A simple CLI tool and TypeScript library for exporting Markdown and CSV files from any Notion.so page. The tool relies on the export feature of Notion's web-app, hence you get exactly the Markdown and CSV you'd get from clicking through: ••• > Export > Markdown & CSV, no subpages, OK.

CLI

The CLI let's you download pages as part of any script, build step or content pipeline. For example, you can use Notion as a CMS to write your blog, export the Markdown in a Github action and build a static Hugo page. 🎉

npm install -g @onebeyond/notion-exporter
notion-exporter 3af0a1e347dd40c5ba0a2c91e234b2a5 -t csv > list.csv

For more options, try notion-exporter --help and read about the needed Cookies.

Library

With the library you can do more elaborate things like directly parse and use your CSV, inject the Markdown in any React/Next.js/Vue page or interact with the underlying AdmZip object.

import NotionExporter from "@onebeyond/notion-exporter"

const tokenV2 = ...
const fileToken = ...
const blockId = "3af0a1e347dd40c5ba0a2c91e234b2a5"
const nofiles = false // download also PDF and image files
const recursive = false // download only blockId

await new NotionExporter(tokenV2, fileToken, nofiles, recursive).getMdString(blockId)

API

Check the doc comments in NotionExporter.ts for the most accurate information.

Constructor

Provide the required Cookies as authentification to create a new exporter client.

const exporter = new NotionExporter(tokenV2: string, fileToken: string, nofiles: boolean, recursive: boolean)

Methods

Download and extract the first file of the requested type and return it as string.

exporter.getCsvString(blockId: string): Promise<string>
exporter.getMdString(blockId: string): Promise<string>

Start an export of the given block and get the exported archive's URL. The second method also downloads the ZIP and gives full access to the AdmZip object.

exporter.getZipUrl(blockId: string): Promise<string>
exporter.getZip(url: string): Promise<AdmZip>

Also chance to unzip all the exported files in the zip in a folder.

exporter.getMdFiles(blockId: string, folder: string): Promise<void>

Needed Cookies

To export anything from Notion, one needs to authenticate oneself with some Cookies (like a browser would). These cookies are called token_v2 and file_token. They are set on all requests of a logged in user when using the Notion web-app.

How to retrieve the Cookies?

  • Go to notion.so.
  • Log in with your account.
  • Open the developer tools of your browser, open Application > Storage > Cookies (Chrome); Storage tab (Firefox).
  • Copy the value of the Cookies called token_v2 and file_token and paste them somewhere safe.

How to get the block ID of a page?

To download a page or table you need its block ID. The block ID is usually the last part of its URL. For example on this page with URL:

https://www.notion.so/Notion-Official-83715d7703ee4b8699b5e659a4712dd8

the ID is 83715d7703ee4b8699b5e659a4712dd8. So you can get the page as Markdown by doing notion-exporter 83715d7703ee4b8699b5e659a4712dd8.

For tables, the ID is the first of the two long hexadecimal strings. Take this gallery for example with URL:

https://www.notion.so/228eea9d563a47f09fc594d0a89a2e18?v=d5bcf2644d2940b1b18a9ba9cc11c9b6

the ID is 228eea9d563a47f09fc594d0a89a2e18. So, you can get the table as CSV by doing notion-exporter 228eea9d563a47f09fc594d0a89a2e18 -t csv.

Note on Stability

This tool completely relies on the export/download feature of the official but internal Notion.so API. The advantage is, that we do not generate any markup ourselves, just download and extract some ZIPs. While the download feature seems to be pretty stable, keep in mind that it still is an internal API, so it may break anytime.

Contributing

Want to help improve this tool, spotted a type or you need to add a new use-case? Please submit issues and PRs on Github.

Contributors