pg
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
buffer-writer | 2.0.0 | 4.12 kB | MIT | prod | |
packet-reader | 1.0.0 | 3.02 kB | MIT | prod | |
pg-cloudflare | 1.1.1 | 5.13 kB | MIT | prod optional | |
pg-connection-string | 2.6.4 | 8.88 kB | MIT | prod | |
pg-pool | 3.6.2 | 68.12 kB | MIT | prod | |
pg-protocol | 1.6.1 | 183.15 kB | MIT | prod | |
pg-types | 2.2.0 | 10.1 kB | MIT | prod | |
pgpass | 1.0.5 | 4.18 kB | MIT | prod |
Pg, or node-postgres, is a non-blocking PostgreSQL client for Node.js. It provides pure JavaScript and optional native libpq bindings, enabling developers to create efficient, low-latency applications. The pg package is built with key features like connection pooling, extensible JavaScript to PostgreSQL data-type coercion, and support for notable PostgreSQL features such as parameterized queries, named statements with query plan caching, asynchronous notifications with 'LISTEN/NOTIFY', and bulk import and export with 'COPY TO/COPY FROM'.
To use pg in your Node.js application, start by installing it from npm using the command npm install pg
. Once the package is installed, you can use it to connect to your PostgreSQL database and perform various operations. Here is a simple example of connecting to a PostgreSQL database and running a query:
const { Client } = require('pg');
const client = new Client({
user: 'db_user',
host: 'database_server',
database: 'database_name',
password: 'db_password',
port: 5432,
});
client.connect()
.then(() => console.log('Connected'))
.then(() => client.query('SELECT * FROM my_table'))
.then(results => console.table(results.rows))
.catch(e => console.log(e))
.finally(() => client.end())
Remember to replace 'db_user'
, 'database_server'
, 'database_name'
, and 'db_password'
with your actual database credentials.
The complete and detailed documentation for node-postgres can be found at the official website https://node-postgres.com. This documentation provides a comprehensive guide on the pg package's API, different supported features, usage examples, and troubleshooting guides. You can also find additional resources on the project's GitHub wiki.