Restart server on crash error

Hi!! I am using pm2 to start the server.

When my api crashes I only have emails to figure it out. But I need to restart the automatic server.

How to do this?

Hi!

PM2 restarts automatically unless you told it not to.

How you start API with PM2?

pm2 start server.js

Then the application crashes. Could you see it’s status in pm2 with pm2 list

I was thinking the application was still running but not in a usable state

2 Likes

That’s good idea to check out.

Other thing that might be useful is checking logs with pm2 logs name/id where name/id is your app name or id in pm2 list

2 Likes

Knex: Timeout acquiring a connection …

But i am using:
const trx = await Database.beginTransaction()
await trx.commit()

await Model.query()
.where(‘id’, field)
.update({
field: 4
})
.transacting(trx)

This sounds a lot like there was connection problem between API and Database.
Maybe DB host / port is wrong or access is not allowed because of some firewall?