I am working with Node.js (express) and MySQL and I have had problems trying to make several queries in the same route. The error it throws is:
Can not set headers after they are sent.
And the code is this:
router.post('/test', function (req, res, next){
db.query("select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where
TABLE_NAME = 'registros';", function (error, results, fields) {
if (error) throw error;
res.render('test', {
columnNames: results
});});
db.query("SELECT * FROM registros", function (error, resp, fields) {
if (error) throw error;
res.render('test', {
dataRegistros: resp
});});
});
I understand that it may be because it is rendering twice in the same route. What would be the correct method to make several SQL queries and return them to a file in view?
Greetings!