I have the same question still trying to figure out a solution.
I was following a tutorial, and I’ve have some methods in a controller to get data from database in SQL Server. Typical CRUD methods, and in each method I’ve wrote
let pool = await sql.connect(config);
I want to optimise the code and call this only once and not everytime in every method, so the connection will be established from the first time I run the code.
Thank you in advance.
>Solution :
Apparently you have to create .js file and add two methods one to get the connection and the other one to close the pool.
Then you import the .js file and use the functions.
Here is an example from David Neal.