node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

Question: is there any method to check whether a client is connected or not

Open bodycombathuang opened this issue 2 years ago • 1 comments

const client=new Client("connectstring"; I know client has connect and end methods to connect to or disconnect from db

1.is there any method to check whether client is in connected state or disconnected state? 2. if client.end() is called, client.connect() cannot be called ,right? I have to create a new instance of Client to connect to db?

bodycombathuang avatar Jun 13 '23 16:06 bodycombathuang

  1. use client.connection._ending which have boolean value. value will be true if the connection already ended, value will be false if connection not yet ended.
  2. yes you must create another client.

CMIIW

Amadeea avatar Jun 06 '25 10:06 Amadeea