Error when 'requir'ing npm modules

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.

https://scripting.getdrafts.com/globals#require

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.

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!!!