louischatriot / nedb

The JavaScript Database, for Node.js, nw.js, electron and the browser
MIT License
13.49k stars 1.03k forks source link

Filename path #459

Open mark89769 opened 8 years ago

mark89769 commented 8 years ago

I can't get nedb to load/creata a database file on a specific location with NWjs. Is this possible? For example I would like to use a single database stored on a network folder for multiple instances of NWjs.

var location= path.dirname(process.execPath)+"\\app\\db\\database.json";
var db = new Nedb({ filename: test, autoload: true });
fpassa commented 7 years ago

What's the file path expected when is compiled into an executable file. For instance, in macOS my project works fine when running it with npm start

But, after packaging it with electron-package and attempting to execute it, the error is appears stating that Uncaught Error: ENOENT: no such file or directory, open filename - datastore.js:77

Where is supposed to be located the db file after application is packaged? Have been tested the NeDB on compiled apps? If so, what's the path to use?

nicolasandrieux commented 7 years ago

I have the same issue, someone have any idea to resolve it.

Oscarato commented 7 years ago

The problem is because the data must located in the user data on windows for example, this mode the app can access to database.

to use: var Datastore = require('nedb'); var userData = app.getPath('userData'); db.banks = new Datastore(userData+'/db/banks.db');

nicolasandrieux commented 7 years ago

@oscarato thx a lot it's working, and I'm learning in same time ;)

javeedrahman commented 7 years ago

Hi @Oscarato i had the same issues and i have tried it this way

var electron = require('electron');
const app = electron.remote.app;
var userData = app.getAppPath('userData');
db = new Datastore({ filename: userData+'/db/persons.db', autoload: true });

but i am getting error in linux and MAC. its only on build. errorpath

Any Idea Please

javeedrahman commented 7 years ago

Hi @Oscarato This is my mistake. Its working fine now. I have used app.getAppPath() instead of app.getPath('userData')

var electron = require('electron');
const app = electron.remote.app;
var userData = app.getAppPath('userData');   <-------- Here i made issues this is app.getPath('userData')
db = new Datastore({ filename: userData+'/db/persons.db', autoload: true });

Thank You :)