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.

ABHILASH SB
  • 2,122
  • 2
  • 21
  • 31

1 Answers1

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)

sihorton
  • 416
  • 2
  • 3
  • 1
    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.. – ABHILASH SB Jul 03 '13 at 11:47
  • 1
    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 http://thechangelog.com/nstore-easy-database-written-for-node-js-in-node-js/ and https://npmjs.org/package/nodejs-microdb for example. – sihorton Jul 08 '13 at 20:28