To connect to the database, import the default database module and provide the necessary options.
The options are as follows:
host(string) the host of your database
port(number) the port to connect on
dbName(string) the name of your postgres database
username(string) the user to connect as
password(string) the users password
connectionString(string) the connection string URI
ssl(object) passed directly to node.TLSSocket, supports all tls.connect options
statementTimeout(number) number of milliseconds before a statement in query will time out, default is no timeout
queryTimeout(number) number of milliseconds before a query call will timeout, default is no timeout
idleInTransactionSessionTimeout(number) number of milliseconds before terminating any session with an open idle transaction, default is no timeout
The package supports TLS/SSL connections to your PostgreSQL server as long as the server is configured to support it. When instantiating a pool or a client you can provide an ssl property on the config object and it will be passed to the constructor for the node TLSSocket. node TLSSocket.
After you create the instance, call
connectDB() to make the connection. Make sure the promise resolves before using the connection any further.