'Change PouchDB directory in Electron

I would like change PouchDB directory in my Electron App. When i update my APP (re-install), all my data are destroyed.

So, i would like change my PouchDB directory for no remove my data when i re-install my App.

My code :

import PouchDB from 'pouchdb';
const Presentation = new PouchDB('~/test/db');

This return an error :

err {type: "OpenError", name: "OpenError", cause: Error: IO error: ~/test/db/LOCK: Aucun fichier ou dossier de ce type, message: "IO error: ~/test/db/LOCK: Aucun fichier ou dossier de ce type", stack: "OpenError: IO error: ~/test/db/LOCK: Aucun fichier…es/abstract-leveldown/abstract-leveldown.js:39:16"}

Anyone know how i can change my directory or just not remove my data when i re-install my Electron App ?

Thank you community !



Solution 1:[1]

~ is a Bash feature called "tilde expansion". It's a function of the shell, electron can't process it. Use new PouchDB('./test/db') record instead.

You can use pouchdb-dump-cli package to export database dump and then import it using pouchdb-load package.

Solution 2:[2]

The IO error is happening because pouch db cannot create the folder in the specified location. Electron apps usually need to store configs, local db files in the appData + appName location. This location has full access to the app.

const appName='<Electron App Name>'
const db = new PouchDB(
    path.join(app.getPath('appData'), appName, "db")
  );

Ref:

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Oleg Shishkov
Solution 2 Amal Chandran