node-postgres README

The project's README from github.com/brianc/node-postgres. As one markdown file: README.md.

node-postgres

Build Status NPM version NPM downloads

Non-blocking PostgreSQL client for Node.js (and bun, deno, cloudflare, etc...). Pure JavaScript and optional native libpq bindings.

Monorepo

This repo is a monorepo which contains the core pg module as well as a handful of related modules.

Install

npm install pg

Documentation

Each package in this repo should have its own readme more focused on how to develop/contribute. For overall documentation on the project and the related modules managed by this repo please see:

:star: Documentation :star:

The source repo for the documentation is available for contribution here.

Features

Extras

node-postgres is by design pretty light on abstractions. These are some handy modules we've been using over the years to complete the picture. The entire list can be found on our wiki.

Support

node-postgres is free software. If you encounter a bug with the library please open an issue on the GitHub repo. If you have questions unanswered by the documentation please open an issue pointing out how the documentation was unclear & I will do my best to make it better!

When you open an issue please provide:

You can also follow me @brianc on bluesky if that's your thing for updates on node-postgres with nearly zero non node-postgres content. My old twitter/x account is no longer used.

Sponsorship :two_hearts:

node-postgres's continued development has been made possible in part by generous financial support from the community.

If you or your company are benefiting from node-postgres and would like to help keep the project financially sustainable please consider supporting its development.

Special thanks to medplum for their generous and thoughtful support of node-postgres!

Medplum logo

Contributing

:heart: contributions!

I will happily accept your pull request if it:

If your change involves breaking backwards compatibility please please point that out in the pull request & we can discuss & plan when and how to release it and what type of documentation or communication it will require.

Setting up for local development

  1. Clone the repo
  2. Ensure you have installed libpq-dev in your system (the native bindings are built in the test process)
  3. From your workspace root run yarn and then yarn lerna bootstrap
  4. Ensure you have a PostgreSQL instance running with SSL enabled and an empty database for tests. note: you can skip the tests requring SSL by setting the environment variable PGTESTNOSSL=1 if you're not changing any SSL related code.
  5. Ensure you have the proper environment variables configured for connecting to your postgres instance. Using the standard PG* environment variables like PGUSER and PGPASSWORD etc...
  6. Run yarn test to run all the tests.

Troubleshooting and FAQ

The causes and solutions to common errors can be found among the Frequently Asked Questions (FAQ)

License

Copyright (c) 2010-2020 Brian Carlson ([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

node-postgres (brianc/node-postgres)

Searching Database…

What is this?node-postgres (pg) is a non-blocking PostgreSQL client library for Node.js — pure JavaScript with optional native libpq bindings. Your JS code uses it to connect to, query, and stream data from a PostgreSQL database.
Is this a standalone app, or something I add to my code?It's a library you install into your JavaScript project, not a standalone app. The repo is a monorepo: the core pg package plus related modules like pg-pool, pg-cursor, and pg-query-stream.
How do I add it to my project?Install the pg package from npm (npm install pg), then create a client or pool with your connection settings and start running queries from your code.
Do I need to install libpq first?No — the default client is pure JavaScript; the native libpq bindings are optional. Both implementations expose the same API, so libpq is only needed if you specifically want the native flavor.
Does it only run under Node.js?Node.js is the main target, but the README says it also runs on bun, deno, and cloudflare, among others. It's a server-side database driver, not a browser library.
Can I use it in commercial projects?Yes — it's MIT-licensed free software, so commercial use, modification, and redistribution are all fine.
What else ships in the monorepo besides pg?pg-pool, pg-native, pg-cursor, pg-query-stream, pg-connection-string, and pg-protocol — separate packages covering pooling, native bindings, cursor-based reads, streaming results, connection-string parsing, and the wire protocol.
Is it actually fast?The README bills it as the fastest PostgreSQL client for Node.js. If you want to push further, the optional native libpq bindings are a drop-in swap since both implementations share the same API.
How mature is this project?Very — it dates back to 2010, has over 13k GitHub stars, and is a fixture of the Node ecosystem. Ongoing development is partly funded by community sponsors, with medplum as a featured sponsor.
Can I stream large result sets instead of loading them all?Yes — the monorepo includes pg-query-stream for streaming rows and pg-cursor for reading results in batches; both are separate npm packages used alongside pg.
What are similar projects?sqlx, pgx, usql, pglite, crystal, pgterm, neon, parse-server
Creator
brianc
Size
5.3 MB
Stars
13.2K
Updated
CommitSep 30
Age
16y
Commits · 90 Days