0
I’m with a Nodejs application that basically has a food search engine. However always in the second research occurs the following exception and I do not know in what part of the code exactly I should open and close a connection with the bank.
(node:22204) UnhandledPromiseRejectionWarning: Error: Cannot use a pool after calling end on the pool
So is my code:
try{
let pool = require ('./conexao');
let res = await pool.query("SELECT * FROM pesquisaAlimentos('?')", [str]);
await pool.end();
return res.rows;
} catch(err){
throw(err);
}
The app.js is like this:
try {
pesqAlimentos(pesq.barraPesq).then(result => {
jsonRes = { "Alimentos" : result };
res.status(200).json(jsonRes);
});
} catch(err){
res.status(500).send(err);
}
My biggest question is whether I should use the pool.end() method and when I should, I’m learning Nodejs now for a college project so I don’t quite understand its workings.