I am using mysql package from https://www.npmjs.com/package/mysql
So basically I have this function in a file:
module.exports.listGames = (id) => {
let query = 'SELECT * FROM test';
if (id) {
query += 'WHERE userid = ' + connection.escape(id);
}
connection.query(query, function(err, results) {
if (err) {
throw err;
}
console.log(results);
});
}
and I want to return those results in the json format
so I can call it in another file which is this function:
function sendGames(req, res) {
const games = db.listGames(req.query.game);
res.json(games);
}
so my question is, How can I return the results from that query?