React app with nodejs/express server and mysql database doesn't load data right away when first visiting the home page. Related to mysql connection
I have an app with the server hosted on heroku where 15 of the latest entries in the database should show up when going to the home page. I have a a conifg.js file where I establish a connection to the database. The code used to be const mysql = require('mysql'); const db = mysql.createConnection({ host: 'host', database: 'db', user: 'user', password: 'password', }); module.exports = db; This was loading the latest entries on the home page properly on first visit but my app was experiencing crashes due to I believe it trying to query without there being a connection? Not entirely sure. I changed this code to const mysql = require('mysql'); let connection=null; function handleDisconnect() { connection = mysql.createConnection({ host: "host", user: "user", password: "password", database: "db" }); // Recreate the connection, s...