Recommand · June 25, 2021 0

Heroku deployment (node.js as backend) giving error consistently

Whenever I redeploy, the code will always run fine, until less than 5 minutes later, where I got status code 503, with code H10. How do we ensure that this error does not persist?

This is the log as shown.

The following is my code (index.js):

express = require("express")
const bodyParser = require("body-parser")
const cors = require("cors")
mysql = require("mysql")
app = express()

app.use(cors())
app.use(bodyParser.urlencoded({extended:true}))
app.use(express.json())

const PORT = process.env.PORT || 3306;

app.set("port",PORT)
const currDate = () =>{
//code
}
// mysql:user:password@host/database

const conn = mysql.createConnection({ //details are censored
    host:"****************",
    user:"**************",
    password:"********",
    database:"***********"
})
conn.connect((err)=>{
    if(err) throw err;
//setting up databases
    conn.query(initRecords,(err,res)=>{
        if(err) throw err;
        console.log("Item Records Done")
    })
    conn.query(initTransactions,(err,res)=>{
        if(err) throw err;
        console.log("Transactions Records Done")
    })

})

app.get("/",(req,res)=>{
    res.send("working!")
})

//the rest are CRUD operations 



app.listen(PORT,()=>{
    console.log(`working at ${PORT}`)
})


The following is in my Procfile:

web: node index.js