How to use sqlite3 module with electron? How to use sqlite3 module with electron? node.js node.js

How to use sqlite3 module with electron?


By far the easiest way to use SQLite with electron is with electron-builder.

First, add a postinstall step in your package.json:

"scripts": {   "postinstall": "install-app-deps"   ...}

and then install the necessary dependencies and build:

npm install --save-dev electron-buildernpm install --save sqlite3npm run postinstall

electron-builder will build the native module for your platform, with the correct name for the Electron binding; and you can then require it in code as normal.

See my github repo and blog post - it took me quite a while to figure this out too.


I would not recommend the native node sqlite3 module. It requires being rebuild to work with electron. This is a massive pain to do - At least I can never get it to work and their a no instructions to for rebuilding modules on windows.

Instead have a look at kripken's 'sql.js' module which is sqlite3 that has been compiled 100% in JavaScript. https://github.com/kripken/sql.js/


Two aspects are to be considered here:

  1. Setting NODE_PATH: this lets electron know where to find your modules (see this answer for a thorough explanation)
  2. Compiling native modules against electron headers: see official docs

And checkout the following questions, that ask the same thing:


My tip would be to give lovefield (by Google) a try.