node.js - Forever monitor and sqlite3 -
my node app returning
error: sqlite_cantopen: unable open database file
my app has following structure:
.controllers/ |--getter.js |--setter.js .system.js .slave.js
system.js
var forever = require('forever-monitor'); var path = require('path'); var relativedir = path.dirname(module.filename); var childworker = new(forever.monitor)(path.join(relativedir,'slave.js'), { max: 3, silent: true, options: [] });
slave.js
... var getter = require('./controllers/getter.js'); var setter = require('./controllers/setter.js'); ...
getter.js/setter.js
var fs = require('fs'); var sqlite3 = require('sqlite3').verbose(); var dbpath = '/absolutepath/db'; if (fs.existssync(dbpath)) { console.log("[getter] db file found"); var db = new sqlite3.database(dbpath, sqlite3.open_readonly); } else { console.log("[getter] cannot find db file"); }
i've tried changing absolute paths relative paths , changing owners of database without luck. app able find database file but, reason can't open it.
after made simple script "test.js" , placed in same dir "system.js". ran it, worked without errors , returned right values.
var sqlite3 = require("sqlite3"); var dbpath = "/absolutepath/db"; var db = new sqlite3.database(dbpath, sqlite3.open_readonly); var sqlquery = 'select lat, long kkk'; db.get(sqlquery, function(err, row) { if (err) { console.log(err); console.log('err!'); } else { console.log(json.stringify(row)); } });
write command " sudo chown www-data. . " in db file directory.
other solution check file exists or not ?
ex :
var fs = require("fs");
var exists = fs.existssync(dbfilepath);
Comments
Post a Comment