Use fs or fs-extra in add-on?

14 views
Skip to first unread message

adamsmith

unread,
Jun 1, 2022, 4:56:53 PMJun 1
to zotero-dev
Quick question: I though from reading https://groups.google.com/g/zotero-dev/c/KjaLwrOKROY/m/Khgbp5xvAQAJ that I can use modules included in Zotero in add-ons.
I have
const fs = require('fs');
in my code and it just stops at this point -- not even throwing an error. (I also tried with fs-extra). Is this supposed to work?

Thanks!
S

Dan Stillman

unread,
Jun 1, 2022, 5:02:42 PMJun 1
to zoter...@googlegroups.com
No, neither of those would work — there's a module system, but that
doesn't mean that built-in Node modules are somehow available in Zotero.

To write to the filesystem from privileged code, you'd want to use
something like `await Zotero.File.putContentsAsync(path, data)`.

https://github.com/zotero/zotero/blob/67700f8a2caa1469ab36d55824c1793e7aa40cc3/chrome/content/zotero/xpcom/file.js#L396-L404

adamsmith

unread,
Jun 1, 2022, 8:40:39 PMJun 1
to zotero-dev
Thanks, that worked on the first try.
Reply all
Reply to author
Forward
0 new messages