Datastore(DB) File is not loading after building in electron APP.

Hi Guys,
I had the same issues and i have tried it this way (my code)

var electron = require('electron');
const app = electron.remote.app;
var userData = app.getAppPath('userData');
db = new Datastore({ filename: userData+'/db/persons.db', autoload: true });

Its working when i run npm start. but after building the APP using electron-builder
i am getting error in linux and MAC. its only on build.

errorpath

Please some help,
Thanks in advance.

1 possible answer(s) on “Datastore(DB) File is not loading after building in electron APP.

  1. Hi guys,

    This is my mistake. Its working fine now. I have used app.getAppPath() instead of app.getPath(‘userData’)

    var electron = require('electron');
    const app = electron.remote.app;
    var userData = app.getAppPath('userData');   <-------- Here i made issues this is app.getPath('userData')
    db = new Datastore({ filename: userData+'/db/persons.db', autoload: true });
    

    I have tested the build in MAC, LINUX UBUNTU and WINDOWS. working fine.

    Thank You 🙂