Node Server Data Base Connection Lost

I’m developing a web app using express, and MySQL. I was able to publish the app on heroku for testing. The problem came after few minutes or seconds, the server throws the following error:

Error: Connection lost: The server closed the connection.
at Protocol.end (/app/node_modules/mysql/lib/protocol/Protocol.js:112:13)
at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:94:28)
at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:526:10)
at Socket.emit (events.js:327:22)

When I restart the server, I’m able to execute some successful calls to database, but after some minutes, the connection get lost.

This is the connection file I’m currently using, I will, change my credentials for placeholders, only for security purppose.

module.exports = {
HOST: 'mysql5044hostname',
USER: 'myUserName',//root
PASSWORD: 'thisIsMyPassword',
DB: 'default_schema'
};

Any help regarding this matter, will be appreciated.

1 thought on “Node Server Data Base Connection Lost”

  1. @vodolaz095 and @riscarrott thanks to both of you, I changed the logic based on the documentation you sent, and I was able to successfully connect to database without losing the communication with the server.

    Reply

Leave a Comment