Import from Notion

Hi everyone, just wanted to share this importer I made. You just need to export your Notion notes, unzip the file, and then run this script using Node.

GitHub Link

There is a little documentation on the GitHub README but I was encouraged to share this point in particular:
Warning: Notion pages that contain parentheses or dashes in the title will have them removed by Notion while exporting your data so the file will be created without them, even though the link itself will still retain them.

13 Likes

Thanks for creating this! Looks good!
I’m excited to try it.


I tested it on macOS Mojave with node 10.13
First try:
Ran node main and when it asked for Notion Export path I dragged the folder over the terminal window (works with most command line utils in macOS).

Got this error:
readline.js:1032
throw err;
^

Error: ENOENT: no such file or directory, scandir '/Users/rsdimitrov/Downloads/Export-b7bea5ff-da8c-48e2-864e-3ee93310425f '

Second try:
Fixed the above error by manually trimming the extra whitespace at the end of the path.
Then got this error
readline.js:1032
throw err;
^

Error: ENOENT: no such file or directory, rename '/Users/rsdimitrov/Downloads/Export-b7bea5ff-da8c-48e2-864e-3ee93310425f\.DS_Store' -> '.DS_Store'
at Object.renameSync (fs.js:591:3)
at fixNotionExport (/Users/rsdimitrov/Downloads/Notion-to-Obsidian-Converter-master/main.js:153:7)
at rl.question (/Users/rsdimitrov/Downloads/Notion-to-Obsidian-Converter-master/main.js:10:17)
at Interface._onLine (readline.js:288:5)
at Interface._line (readline.js:638:8)
at Interface._ttyWrite (readline.js:919:14)
at ReadStream.onkeypress (readline.js:168:10)
at ReadStream.emit (events.js:182:13)
at emitKeys (internal/readline.js:424:14)
at emitKeys.next (<anonymous>)

Third try:
Deleted .DS_Store folder from the root path
Then got this:

readline.js:1032
        throw err;
        ^

Error: ENOENT: no such file or directory, rename '/Users/rsdimitrov/Downloads/Export-b7bea5ff-da8c-48e2-864e-3ee93310425f\Inbox aa646ee03f274e3c8053c8ae3f794295.md' -> '/Users/rsdimitrov/Downloads/Export-b7bea5ff-da8c-48e2-864e-3ee93310425f\Inbox.md'
    at Object.renameSync (fs.js:591:3)
    at fixNotionExport (/Users/rsdimitrov/Downloads/Notion-to-Obsidian-Converter-master/main.js:153:7)
    at rl.question (/Users/rsdimitrov/Downloads/Notion-to-Obsidian-Converter-master/main.js:10:17)
    at Interface._onLine (readline.js:288:5)
    at Interface._line (readline.js:638:8)
    at Interface._ttyWrite (readline.js:919:14)
    at ReadStream.onkeypress (readline.js:168:10)
    at ReadStream.emit (events.js:182:13)
    at emitKeys (internal/readline.js:424:14)
    at emitKeys.next (<anonymous>)

Judging by the errors your script assumes I’m not on an unix-based system and my filesystem uses backslashes \ instead of forwardslashes /

Suggestions

Make it accept command line parameters instead of asking for the path once the script is run. This way I can use the autocomplete function of the bash/terminal and construct the correct path easier.

Also, I think this article will help: https://shapeshed.com/writing-cross-platform-node/

Edit: Fixed it to run without errors on macOS by changing line 144 from
var currentPath = path + '\\' + currentDirectory[i].name;
to
var currentPath = path + '\/' + currentDirectory[i].name;

3 Likes

Hi, @rsdimitrov, thank you for finding that issue. I had to make a previous change because a user found it wasn’t working on Ubuntu. I’m sorry I’m just now seeing this; I don’t get on the forum frequently and I only get notifications for GitHub issues. I’ll make this an issue and get around to fixing it as soon as I get the free time.

Thank you for trying it out and letting me know the issues you came across!

2 Likes

Thanks. I got it to work under Linux. For others, if you want to run javascript from the terminal, your need to install nodejs first. Install command:
sudo apt install nodejs

1 Like

I made a hacky fix, node supports paths on most OSes with path.sep. I made a pull request to your repo here :slight_smile:
https://github.com/connertennery/Notion-to-Obsidian-Converter/pull/9

2 Likes

tnx! works awesome without errors. win10

1 Like

Didn’t have luck getting the script to recognize the file path for my notion export in Linux (elementary OS). Could very well be my own error. Ran flawlessly in mac OS.

Thank you for sharing!

1 Like

I’m sorry noob question but i just bought a Mac and don’t find a way to run it. It open in firefox. :frowning:

You need to install nodejs from official site Download | Node.js
and then run the script with node:
node main.js

AWESOME thanks!!

Works very well. Thank you :pray:

Hi, could someone please explain this more directly & simply?
I am a mac user trying to figure out how to do this, but my knowledge is lacking. I installed the nodejs, but am not sure how to run the script, nor how to do that with the node.
I’d appreciate any help I can get!!

Hi @rail

Thanks for putting the effort into developing this tool. FYI I had this error when I tried to run it.

/main.js:27
	let bn = npath.basename(name);
	^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:968:3

Hi @froggy, I just did this on my MacBook Pro (Big Sur 11.4). Here are the steps I used (apologies if they are too pedantic, I am not sure what level of understanding you are at). There’s a couple of things that could go wrong in this process, so feel free to reply with any errors.

  1. Check to make sure you have Node.js installed by opening a Terminal and typing in node -v. It should come up with a version number rather than ‘command not found’.
  2. Get the script from OP (@rail)'s public GitHub repository onto your own machine. The file you need is main.js. You can do this in a couple of ways:
    • Clone the repository locally, onto your own machine. (If you have Git and know how to use it, this is probably the easiest option.)
    • Download the whole repository as a ZIP file and unzip it locally to get the files. You can see the option to download the ZIP under the bright “Code” menu in the homepage of the GitHub repo (here).
    • Download the individual file by looking at the “Raw” verison of it on GitHub. In other words, save this file.
  3. If you haven’t already, export the Notion workspace (or individual page/databse) that you want to convert as “Markdown + CSV”, and save it somewhere locally (unzipping as necessary). Take note of the path to the top-level directory of the unzipped export.
  4. Open a Terminal window and navigate to the directory that contains the script (the one you cloned or saved the script to).
  5. Once there, start the script execution using the command node main in Terminal.
  6. The script will prompt you to enter the absolute directory of your exported Notion files (this is the top-level directory that I mentioned in step 3).
  7. Once you enter that directory, and assuming everything went well, the script will execute the conversion, and tell you how many files were converted, how long it took, etc.

That’s it! If you check the directory of your Notion exports you should see that the markdown filenames have changed, the links etc. inside are converted to an Obsidian-readable format, and you have a new markdown file with a markdown table for every CSV file in the original export.

Hope this helps :slight_smile:

BTW @rail, thanks for this nice little tool. Really easy and simple, and saved me some time and trouble!

1 Like

Im sorry maybe im not understanding the path syntax correctly. Im using wsl and when i enter the path I get the following error.

Error: ENOENT: no such file or directory

I’ve input the path in the following ways.

"D:\Documents\DnD c3206f0c6b864fbc87eb015f865154fd"
D:\Documents\DnDc3206f0c6b864fbc87eb015f865154fd
"D:\Documents\DnDc3206f0c6b864fbc87eb015f865154fd"
D:\Documents\DnDc3206f0c6b864fbc87eb015f865154fd
D:/Documents/DnDc3206f0c6b864fbc87eb015f865154fd
"D:/Documents/DnD c3206f0c6b864fbc87eb015f865154fd"

-moved extraction to the same drive as my IDE here

'/mnt/c/Users/user/Documents/Code/Extraction/DnD c3206f0c6b864fbc87eb015f865154fd'

Can someone lend a hand? The path im putting in should be the folder extracted from the Zip correct? Screenshots would be a massive help.