Trying to send data to EJS from MySQL Databases using Node.js and Express, but it shows error when returning 'results' parameter:
function dbData(){ connection.query('SELECT * FROM clients', (err, results, fields)=>{ return results; }); }
Route:
app.get('/', (req, res)=>{ let data = dbData(); console.log(data); });
And when going to localhost:3000, the console shows:
The thing is that when i console log the results:
connection.query('SELECT * FROM clientes', (err, results, fields)=>{ console.log(results); return results; });
The console shows:
So why data is equal to 'undefined' if i'm returning the 'results' array? and how can i solve this?
I'm new in Node.js, sorry if this is too obvious :(
https://stackoverflow.com/questions/67376994/undefined-when-returning-results-parameter-from-mysql-query May 04, 2021 at 07:32AM
没有评论:
发表评论