How to work in NodeJS with PostgreSQL?

Don't you know how to operate a pool of customers. I have required multiple applications to simultaneously use a single Postgre database.
Reading the article: https://node-postgres.com/features/pooling face expression:
You must __always__ return the client to the pool if you successfully check it out, regardless of whether or not there was an error with the queries you ran on the client. If you don't check in the client, your application will leak them and eventually your pool will be empty forever and all future requests to check out a client from the pool will wait forever.

Do not understand anything. I'm doing queries like this:
const {Pool} = require("pg");
const pool = new Pool({
 host: "127.0.0.1",
 port: 5432,
 database: "mydb",
 user: "user1",
 password: "pwd",
});
(async () => {
 let query = "SELECT datnameasfd FROM pg_database;";
 let res = await pool.query(query);
})();

Is that correct or not? But there is not even the client. Don't know whether you want it to do and in what case you need. How to change the implementation if I have a web server handles hundreds of requests and have persistent-connection? In any case, in the end you need to add pool.end()?
April 7th 20 at 10:55
1 answer
April 7th 20 at 10:57
Solution
Stored in the pool of connections, say 10 pieces. Every time we called pool.query(), we requested the connection. If the connection is there - the request is made, and then in the pool is updated its status to free. If all connections are busy - waiting until the first. The documentation also says that you should return connection in the pool (otherwise when the limit of connections in the pool, requests will wait indefinitely). And pool.end() need to call when you no longer need the current pull requests, for example you have temporarily created for a different database? The pull itself will create connections as needed, of course it will not go beyond the limits, otherwise we would spend all the resources on creating connections.

Find more questions by tags PostgreSQLNode.js