This leaflet example (Leaflet.TileLayer.PouchDBCached) is using an "idb" adapter and for electron/node it looks like I want to use a "leveldb" adapter. So I followed the instructions here: PouchDB in Node.js
In Node.js, the adapter situation is much simpler than in browsers. By default, if you create a PouchDB like this one:
var pouch = new PouchDB('./path/to/db');
then a LevelDB-based database will be created in the directory ./path/to/db. The LevelDB implementation uses LevelDOWN.
In my "main.js" (Electron entry point) I create a db like this:
var dbPath = path.join(__dirname, 'main-db');
var myDB = new PouchDB(dbPath);
console.log('myDB', myDB.adapter);
And though the adapter type is reported as "leveldb" it does not show up on disk.
Question: Where is the database created? I've looked in my app directory, in the node_modules/pouchdb directory. I've even looked for "hidden files" (this is on OSX). What gives? If I dump the db instance to the console, it looks like it was created (in memory). Am I "doing it wrong"?
So it turns out I had a couple of things going wrong.
The path I was using was incorrect. Even though I was trying to create the pouchDB instance from a Javascript file attached to an index.html file inside my app folder, this path did not work:
'./db/todo-db'
. I was able to create the db instance using this path:'./app/db/todo-db'
.This seems odd to me and I don't understand it. The
__dirname
reports that my JS context was'./path/to/app/
– so I am already inside the app folder.I was getting an error message about a mismatch between the NODE version which levelDB (the adapter I was requesting) was compiled for. I was able to solve this by using electron-rebuild in a postinstall call:
In my package.json: