Question

Local database in Appjs is not persisting after the application is closed. Whenever the application is opened it is creating a new database and couldn't find the previously created one. Please provide me a solution for this.

Was it helpful?

Solution

what kind of database are you using? Nodejs can connect to many different types of database like sqlite, mysql, postgres and mongodb. In app.js you can use the constant: __dirname to get the path of the currently executing script so if you are using sqlite3 or simliar then you can put the database into the local directory.

If you are trying to use indexedBD or simliar then I just searched on the issues on github. Milani has the following solution in app.js, you should set a directory to use to persist the data:

var app = require('appjs');
var path = require('path');
app.init({
    "CachePath":path.resolve(__dirname,"./data") // change to whatever path you like
});

Then in the browser / index.html:

window.localStorage.setItem('test5','test5 content');
var test = window.localStorage.getItem('test5');

If localStorage works then hopefully database access can also work for you. (See the issue here: https://github.com/appjs/appjs/issues/169)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top