Home > Back-end >  Connect Node.js to Microsoft SQL Server
Connect Node.js to Microsoft SQL Server

Time:01-07

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.

CodePudding user response:

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.

  •  Tags:  
  • Related