I'm trying to output code from an SQLite3 database with Javascript and Node.js, it selects the correct data and outputs each row to the console but doesn't add it to a JSON file using the code below:
var obj;
db.serialize(function(){
req = sqlRequest;
console.log(req); //sql request to console
db.each(req, function(err, row){
console.log(row); //outputs every entry correctly
obj += row;
});
db.close();
});
console.log(JSON.stringify(obj));
fs.writeFile(sqlRequest, JSON.stringify(obj), function(err){
if(err){
return console.log(err);
}
else
{
console.log("Json saved to: " + sqlRequest);
}
console.log("The file is saved");
});
Any suggestions?
Aucun commentaire:
Enregistrer un commentaire