1
I am developing a project in Nodejs and at the moment, I am facing some problems when returning some value of a function within a module.
Code:
Archive for queries
async function query(query){
con.connect(function(err) {
if (err) throw err;
con.query(query, function (err, result) {
if (err) throw err;
const response = {
status: true,
data: result
};
return response;
});
});
}
// Teoricamente, era para a função query() retornar um JSON ao chamá-la
module.exports = query;
Controller file
const conn = require('../sealed/con');
module.exports = {
async index(request, response){
const splans = await(conn(`SELECT * FROM table`));
console.log(splans);
}
};
When calling the function within my controller, it is returned only undefined
, but if I give a console.log
in function query
, works normally, the problem is that I need these values returned in my controller.