I am new to Electron (Atom-shell), and I am trying to load a NodeJS plugin into the application I am building, but I don't know how. The documentation is not clear on that.
For instance, I am trying to use sqlite3 plugin in my app, I used npm install sqlite3
, and it was successfully installed. But the application throws and error when I try to call it var sqlite = require('sqlite3')
. Are there any further steps I am not aware of ?
Thanks.
For pure JS (i.e. not native) modules you need the following:
package.json
dependenciesexport NODE_PATH=/PATH/TO/node_module
)The first requirement is obvious and the second has its roots in this issue.
For native node modules (such as
sqlite3
) which use C++ bindings, you need to build them against electron headers to work. According to electron docs, the easiest way to do that would be:To install the npm modules correctly you should go into the folder of your electron app and install the module via npm.
The flag --save is important, because npm will install the module inside your app.
Afterwards the require should work.