lundi 27 avril 2015

Express - why does code never return?

I'm an Express rookie, and don't understand: Why does the following code never return? It just seems to hang.

router.post('/post',function(req,res){

    var file = "test.db"
    var exists = fs.existsSync(file);
    if(!exists) {
        console.log("Creating DB file.");
        fs.openSync(file, "w");
    }
    var sqlite3 = require("sqlite3").verbose();
    var db = new sqlite3.Database(file);

    db.serialize(function() {
        if(!exists) {
            db.run("CREATE TABLE Stuff (thing TEXT)");
        }
        var stmt = db.prepare("INSERT INTO Stuff(thing) VALUES (99999)");
        stmt.finalize();
    });

    db.close();
}); //seems to hang at this line.

Aucun commentaire:

Enregistrer un commentaire