I am going to develop a REST service with Node Js, using mysql2 module and its pool API.
My question is:
what is the way to deal with ending connections to databases a rest api service?
A single client request may need to do multiple queries to database, so my opinion is that it's best to close the database connection after every request, not every query of course.
But I read that pools close connections automatically so the other option I have is not bothering about this problem at all.
What is your advice?
Asked
Active
Viewed 19 times
0

Ferex
- 553
- 6
- 22
-
close and use a connection pool. That's what they are for – OldProgrammer Jun 17 '23 at 22:02
-
@OldProgrammer sorry I don't get you, you say close, I am asking when, when to close – Ferex Jun 18 '23 at 07:11
-
close the connection after you are done with it in the REST call. – OldProgrammer Jun 18 '23 at 11:53