I have a hard time being able to chain functions in node.js, i can't get the receiver to wait. Shouldn't promises be asynchronous and therefore suited for such a task?
const promise = new Promise((resolve, reject) => {
var input = 'SELECT * FROM ideas;';
connection.query(input, (err, results) => {
if(err) {
console.log(err);
reject();
} else {
console.log('success');
results = JSON.stringify(results);
console.log(results);
resolve();
return results;
}
})
});
promise.then(function(results) {
results = JSON.parse(results);
console.log(results);
});
I hope someone knows what I am missing here and can help!
require('mysql2/promise');, then you can use built-in promise support with your database rather than manually promisifying each operation.