I followed a tutorial to send query results obtained from pg to response.json in node.js and express.js . code given below
const getUsers = (request, response) => {
pool.query('SELECT * FROM users ORDER BY id ASC', (error, results) => {
if (error) {
throw error
}
response.status(200).json(results.rows)
})
}
but I am not to find any tutorial to send multiple query results something like below.
const getUsers = (request, response) => {
pool.query('SELECT * FROM users ORDER BY id ASC', (error, results1) => {
if (error) {
throw error
})
}).then( pool.query('SELECT * FROM provider ORDER BY id ASC', (error, results2) => {
if (error) {
throw error
}
response.status(200).json({"query1":results1.rows, "query2":results2.rows} )
}
})