typicode / lowdb

Simple and fast JSON database
MIT License
21.39k stars 921 forks source link

Saving db.json to a custom location on the computer #214

Closed kudapara closed 7 years ago

kudapara commented 7 years ago

Hello. Is it posible to save the database on a custom directory on the computer e.g Documents folder? I am using lowdb in an electron app.

I understand this code saves the db.json in the same folder as the app.

const low = require('lowdb')
const FileSync = require('lowdb/adapters/FileSync')

const adapter = new FileSync('db.json')
const db = low(adapter)

But if i try something like

const adapter = new FileSync(require('electon').app.getPath('Documents') + '/db.json')

I get an error. Please help.

josselinchevalay commented 7 years ago

could you share your error message ?

kudapara commented 7 years ago

Oops after doing some research I discovered that this is an issue related with electron. Somehow require('electron').app is undefined when I write it in the renderer.js file but it works in the main.js file.