1

I've a function that makes a simple pgsql query which I'd like returned to the const variable it's declared in, so I can access it in other parts of the code.

const Id = client.query(idQuery, (err, result) => {
    if(err) {
        console.log(err);
    }
    const Data = result.rows;
    if(Data == undefined) {
        console.log("Running query ...");
    } else {
        console.log("Done.");
    }
    return Data;
})

Yet, if I try to assign its value like so: const testVar = Id, the value is always undefined. The same is true if I console.log(Id). There's probably something very simple that I'm glancing over, but I've declared other functions similarly with successful output.

0 Answers0