nedb
nedb copied to clipboard
Nedb not working after packaging Electron App.
I use Nedb for loading and saving notes. However, after I packaged my Electron App.
Code in index.js
var userData = app.getAppPath('userData'); let db_graphs = new Datastore({ filename: userData+'/graphs.db', autoload: true}); db_graphs.loadDatabase();
I hit the same issue @zlindaz2411
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
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! 😭
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
});