0

I couldn't find the local database path in Appjs. But still I could create local database in appjs, but after reopening the application the created database is not existing. Whenever I open the application it is creating a new database. I need to keep this database even after closing the application.

1
  • In order to help you please add better explanation what kind of database are you trying to connect along with the corresponding code. Commented Jul 2, 2013 at 12:51

1 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

2 Comments

I need to develop a portable appjs application, So it's not possible install sqlite via npm. I tried using web sql database, but I couldn't reuse the data once written in the database even after setting the cache path too..
There are lots of alternative databases for nodejs, I guess you need an in-process database if you want it to be portable. If you are happy with a nosql type approach then there are lots of options. I just searched google and found thechangelog.com/… and npmjs.org/package/nodejs-microdb for example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.