You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to get data onto a web page from an sqlite3 database in my Express app I have following in my route file
var express = require('express');
var router = express.Router();
var fs = require("fs");
var file = "./database/testDB.db";
var exists = fs.existsSync(file);
var sqlite3 = require("sqlite3").verbose();
var db = new sqlite3.Database(file);
/* GET home page. */
router.get('/', function(req, res, next) {
var data = 'Data Starts';
db.serialize(function() {
db.each("SELECT id, as_nr FROM Autonomous_systems", function(err, row) {
console.log ('--'+row.id + ": " + row.as_nr);
});
});
db.close();
console.log (data);
res.render('index', { title: 'Express', datax: data });
});
module.exports = router;
When I load the page in browser I get the page for the first time and the rows printed on console.
but when I reload the page I get following error
Data Starts
--29: 25648/53265
--30: 5555
--31: 5559
GET / 304 76.742 ms - -
GET /stylesheets/style.css 304 4.419 ms - -
/home/ehsan/n_ode/Tutorials/sqliteTest/routes/index.js:24
console.log ('--'+row.id + ": " + row.as_nr);
^
TypeError: Cannot read property 'id' of undefined
at /home/ehsan/lude the following file with any support request:
npm ERR! /home/ehsan/n_ode/Tutorials/sqliteTest/npm-debug.log
n_ode/Tutorials/sqliteTest/routes/index.js:24:28
at Database.errBack (/home/ehsan/n_ode/Tutorials/sqliteTest/node_modules/sqlite3/lib/sqlite3.js:16:21)
at Database.each (/home/ehsan/n_ode/Tutorials/sqliteTest/node_modules/sqlite3/lib/sqlite3.js:20:25)
at Database.<anonymous> (/home/ehsan/n_ode/Tutorials/sqliteTest/routes/index.js:23:8)
at /home/ehsan/n_ode/Tutorials/sqliteTest/routes/index.js:22:5
at Layer.handle [as handle_request] (/home/ehsan/n_ode/Tutorials/sqliteTest/node_modules/express/lib/router/layer.js:95:5)
at next (/home/ehsan/n_ode/Tutorials/sqliteTest/node_modules/express/lib/router/route.js:131:13)
at Route.dispatch (/home/ehsan/n_ode/Tutorials/sqliteTest/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/ehsan/n_ode/Tutorials/sqliteTest/node_modules/express/lib/router/layer.js:95:5)
at /home/ehsan/n_ode/Tutorials/sqliteTest/node_modules/express/lib/router/index.js:277:22
npm ERR! Linux 3.16.0-60-generic
npm ERR! argv "/home/ehsan/.nvm/versions/node/v4.2.4/bin/node" "/home/ehsan/.nvm/versions/node/v4.2.4/bin/npm" "start"
npm ERR! node v4.2.4
npm ERR! npm v2.14.12
npm ERR! code ELIFECYCLE
npm ERR! sqliteTest@0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the sqliteTest@0.0.0 start script 'node ./bin/www'.
npm ERR! This is most likely a problem with the sqliteTest package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./bin/www
npm ERR! You can get their info via:
npm ERR! npm owner ls sqliteTest
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/ehsan/n_ode/Tutorials/sqliteTest/npm-debug.log
The text was updated successfully, but these errors were encountered:
I am trying to get data onto a web page from an sqlite3 database in my Express app I have following in my route file
When I load the page in browser I get the page for the first time and the rows printed on console.
but when I reload the page I get following error
The text was updated successfully, but these errors were encountered: