I am trying to run something like:
var x = require(‘sqlite3’)
but I always get the error:
‘Script Error: Error: The file “sqlite3” couldn’t be opened because there is no such file.’
I have tried installing the module globally using:
npm install -g ‘sqlite3’
which works and (on my MacBook) installs it in /usr/local/lib/node_modules, but still gives the error.
Where am I going wrong?
Require for Drafts scripting work is as set out here.
Note that node.jsis not a core part of JavaScript or part of Drafts, so you need to use a non-node version in Drafts.
Fuzzball is a Node library . It can only run inside of Node, which is its own platform and not part of the core JavaScript language. Node adds a lot of API and supporting frameworks that are not part of core JavaScript language (like DOM processing).
Drafts’ native JavaScript environment is based on JavaScriptCore and is not appropriate for execution of Node libraries.
In some cases Node libraries provide versions of their library that can run outside of Node, but I don’t see that noted as an …
Ahhh. Thank you very much. For some reason I made the dumb assumption that I could run Node stuff. Thanks very much.
1 Like
If you have Node on your system, you can interact with it via the ShellScript object in scripts - triggering scripts and getting results.
That is very clever. Thank you. What I assume you mean is to create a shell script that runs a node script and returns the results that can then be used in Drafts in another Javascript script.
BTW Love your application. Plan on using it a massive amount this year. Listened to your Automators podcast 2-3 times!!!