Saturday, December 16, 2017

PouchDB in Electron, set data storage location

Leave a Comment

I am writing an Electron application that will need to store a large amount of data on the client. I want to use PouchDB but I need to have control over the location where the database is held on the user's PC. I can't find anything in the docs about it.

1 Answers

Answers 1

Setting the location of the database is very simple.

db = new PouchDB(dbFilePath); 

You can set the dbFilePath to the path that you want. For example, I want to set the path to where the Electron application runs. So I do the following.

const appDataDirectory = app.getPath('appData'); let dbFilePath = appDataDirectory + '/data/'; if (process.env.NODE_ENV === 'development') {   dbFilePath = './data/'; } log.debug('NODE_ENV:%s, dbFilePath:%s', process.env.NODE_ENV, dbFilePath); let db = new PouchDB(dbFilePath); 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment