nedb icon indicating copy to clipboard operation
nedb copied to clipboard

Nedb not working after packaging Electron App.

Open zlindaz2411 opened this issue 5 years ago • 4 comments

I use Nedb for loading and saving notes. However, after I packaged my Electron App. Screenshot 2019-12-23 at 00 23 39

Code in index.js

var userData = app.getAppPath('userData'); let db_graphs = new Datastore({ filename: userData+'/graphs.db', autoload: true}); db_graphs.loadDatabase();

zlindaz2411 avatar Dec 22 '19 23:12 zlindaz2411

I hit the same issue @zlindaz2411

joephon avatar Mar 08 '20 16:03 joephon

I am having the same issue, I set up NEBD following this article, and packaged following these instructions. I am not sure where to start debugging the packaging process.

Have you found any solutions yet? @zlindaz2411 @joephon

Lastofthefirst avatar Mar 15 '20 19:03 Lastofthefirst

attn - @zlindaz2411 @joephon @Lastofthefirst

Have any of you tried using path.join() when declaring your Datastore?

This issue happens a lot in the Electron universe, and it's not really an issue with nedb, but rather static file paths.

Give something like this a go:

const path = require("path");
let db_graphs = new Datastore({ filename: path.join(userData, 'database.db'), autoload: true});

Also, try changing the location of the .db file and/or utilize the process API:

const path = require("path");
let db_graphs = new Datastore({ filename: path.join(process.env.APPDATA, 'database.db'), autoload: true});

I'm curious – Don't have time to test, but let me know what happens! I know one of these methods (or one similar) work, but it's been years so I forget which method is the ticket! 😭

alectrocute avatar May 06 '20 21:05 alectrocute

Thanks for the reply, here is what ended up working for me:

const dbFactory = (fileName) => Datastore.create({ filename: (process.env.NODE_ENV === 'dev' ? ${__dirname}/.. : process.resourcesPath) + /data/${fileName}, timestampData: true, autoload: true });

Lastofthefirst avatar May 07 '20 03:05 Lastofthefirst