Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Connect Node.js to Microsoft SQL Server

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading