As it already answered above - your function returns Promise, so result will be defined only when promise will be resolved (or will not be defened if promise will be failed).
The best practice here is build your async program by the way, when all code, which requires result will be placed on result/reject Promise callbacks:
var data = sql.execute({query:"select * from Profile_User"}).then(function (result){
console.log("Received data"+JSON.stringify(data));
// doing anything with data
}, function( err ) {
console.log( "Something bad happened:", err );
});
If you need to "wait" while promise will be resolved - you can use new async/await feature, but you may understand, thit this stuff will stop your thread execution until promise resolution.
In that case you need to wrap your async code to another async function, like this:
async executeSQLAndDoSomething () => {
try {
var data = await sql.execute({query:"select * from Profile_User"}) // Will be thread stop here
console.log(data)
// Doint something with data
} catch (err) {
// ... error checks
}
}
Read more info about async/await here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await