Lowdb "Uncaught Error: EACCES: permission denied, open 'db.json'"


#1

My app is using https://www.npmjs.com/package/lowdb to store data in a flat file.

const low = require(‘lowdb’);
const db = low(‘db.json’);

This works fine while developing the application however when I compile the dmg and install the app I am getting “Uncaught Error: EACCES: permission denied, open ‘db.json’”.

My guess is that the json file should stored somewhere more user specific but I’m unsure how to do that and still make the application cross OS compatible. Any help would be appreciated! Thanks


#2

This module solved my problem and allowed me to store the db.json file in the users config folder. https://www.npmjs.com/package/appdirectory


#3

Electron provides the app.getPath('userData') API for this purpose.