I’m developing some functions with serverless with the nodejs template. I have a service that connects to a mysql database and retrieves some data. Everything is fine when I make the first call, but when I repeat it I receive an error because the connection was closed.
I managed to get it working creating the connection in each of the handlers, but I don’t like this solution for several reasons:
- It will not give a good performance (creating the connection on each call)
- It not scales well. It’s restricted to the maximum number of simultaneous connections.
I read about the lib folder, creating the connection on a module placed there and then requiring that connection, but it doesn’t work either.
Am I right with this thougts? Or we must create a db connection on each call?
Thanks in advance