I have a db.js file that has this line at the top for connecting to a database. I call this file to start requests from other js files:
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('./mydatabase');
db.serialize(function() {
db.each("SELECT rowid AS id, info FROM lorem", function(err, row) {
console.log(row.id + ": " + row.info);
});
db.close();
If I require () this file above 4 times in different files, does this mean that the sqlite database will be initialized many times?
I want to initialize it only for the first time.
Is it really ineffective? Is there a more efficient way?
source
share