Doing MySQL connection right in Express

Sai Umesh Dhanewar
Tech Buddy
Published in
1 min readFeb 13, 2018

Joey..for no reason :-)

When I started learning express, I was working with MySQL database.

there are many tutorials which explains how to connect MySQL database in express framework. unfortunately many of them miss very important thing while connecting MySQL database in express is releasing connection once you are done with it.

releasing connection after every time you use it is painful and if you forget to release connection, then it will create lot problems such hanging application while connecting to database which is really bad experience for user and developer as well. since I was new to development that time it was very frustrating for me to face all these problems.

After working with express for couple of months with MySQL, I’ve changed my strategies in connecting database and it yielded great results. good thing about this is you don’t have to remember releasing the connection :-). my code as follows.

remember I’m connecting MySQL using middleware.

--

--