How to make SQLite to work with Angular 4+, Electron and NodeJS

Haris Hajdarevic picture Haris Hajdarevic · Sep 6, 2017 · Viewed 7.4k times · Source

I'm trying to build one small desktop app using:

  • Angular 4+
  • NodeJS
  • Electron
  • SQLite3

NodeJS will be used for scanning local user hdd and inserting specific files that are found into SQLite3 database.

I checked dozens of documentation and suggestions. Most of them suggest to use NodeJS express framework and make layer between Angular 4+ -> Express -> SQLite3.

I want to avoid using express framework because it is going to be desktop app and it is not needed at all.

What I tried and what I did:

I installed:

   "sqlite3": "^3.1.9",
   "node-pre-gyp": "^0.6.36",

as dependencies in my project.

Than I have read if you want to use native nodejs library you should run electron rebuild. So I installed also electron rebuild:

"electron-rebuild": "^1.6.0"

as a devDependencies and run it with following command:

./node_modules/.bin/electron-rebuild

Rebuild sqlite3 successfully finished.

Than I run electron application and I get following error:

/~/node-pre-gyp/lib/node-pre-gyp.js
Module build failed: Error: ENOENT: no such file or directory, open '/home/haris/development/walter/angular-electron-starter/node_modules/node-pre-gyp/lib/node-pre-gyp.js'
    at Error (native)
 @ ./~/sqlite3/lib/sqlite3.js 1:13-36
 @ ./src/app/home/home.component.ts
 @ ./src/app/home/index.ts
 @ ./src/app/app.module.ts
 @ ./src/app/index.ts
 @ ./src/main.browser.ts
 @ multi (webpack)-dev-server/client?http://localhost:3000 ./src/main.browser.ts

I stuck here. I tried many more things like:

1. Removing node_modules
2. npm install --build-from-source

but still I'm getting the same error.

Any suggestion or help will be very appreciated.

Answer

leota picture leota · Oct 12, 2017

I've just published a sample project which shows how to build a desktop app using Electron, Angular4 and Sqlite3. You can clone it here

Note I've node-gyp globally installed.

Hope it helps