{"id":16483,"library":"pg-database-url","title":"PostgreSQL Connection URL Builder","description":"pg-database-url is a minimalist utility that constructs a PostgreSQL connection string (URI) from a structured JavaScript configuration object. Released as version 0.1.0, this package targets older Node.js environments (specifically `>=4.2.0`) and exclusively uses CommonJS modules. As of the last observed activity, the project appears to be abandoned, with no significant updates or maintenance in recent years (last commit over 11 years ago). Its primary function is to simplify the creation of connection strings for use with PostgreSQL client libraries like `node-postgres`, converting host, port, database, username, and password into a standard `postgres://` URI format. It does not offer advanced features like connection pooling, query building, or extensive validation, focusing solely on the URI generation aspect. There are no clear release cadences or stated differentiators, as it is a very specific, single-purpose library.","status":"abandoned","version":"0.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/mediasuitenz/pg-database-url","tags":["javascript","postgres","pg","database","url","connection string"],"install":[{"cmd":"npm install pg-database-url","lang":"bash","label":"npm"},{"cmd":"yarn add pg-database-url","lang":"bash","label":"yarn"},{"cmd":"pnpm add pg-database-url","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is CommonJS-only, as indicated by its `require` usage in the README and its age. ESM `import` statements will fail.","wrong":"import pgUrl from 'pg-database-url'","symbol":"pgUrl","correct":"const pgUrl = require('pg-database-url')"},{"note":"The package exports a single default function, not named exports. Destructuring `pgUrl` will result in `undefined`.","wrong":"const { pgUrl } = require('pg-database-url')","symbol":"pgUrl","correct":"const pgUrl = require('pg-database-url')"}],"quickstart":{"code":"const pgUrl = require('pg-database-url');\n\n// Basic configuration from environment variables or a config file\nconst dbConfig = {\n  host: process.env.DB_HOST ?? 'localhost',\n  port: parseInt(process.env.DB_PORT ?? '5432', 10),\n  database: process.env.DB_NAME ?? 'mydb',\n  username: process.env.DB_USER ?? 'user',\n  password: process.env.DB_PASSWORD ?? 'pass'\n};\n\nconst connectionString = pgUrl(dbConfig);\nconsole.log('Generated Connection String:', connectionString);\n\n// Example with `node-postgres` (install separately: npm install pg)\n// const { Client } = require('pg');\n// const client = new Client({ connectionString });\n//\n// async function testConnection() {\n//   try {\n//     await client.connect();\n//     const res = await client.query('SELECT NOW() as current_time');\n//     console.log('Database time:', res.rows[0].current_time);\n//   } catch (err) {\n//     console.error('Database connection error:', err);\n//   } finally {\n//     await client.end();\n//   }\n// }\n//\n// testConnection();","lang":"javascript","description":"This quickstart demonstrates how to generate a PostgreSQL connection string from a configuration object, suitable for use with client libraries like `node-postgres`. It includes placeholder environment variables for security and best practices."},"warnings":[{"fix":"Consider migrating to actively maintained alternatives like `pg-connection-string` (from the `node-postgres` ecosystem) or manually constructing connection URIs, ensuring proper URL encoding of credentials.","message":"The package `pg-database-url` is version 0.1.0 and has not been updated in over 11 years. It is effectively abandoned, meaning no new features, bug fixes, or security updates will be provided. Using unmaintained software can pose significant security risks and compatibility issues with newer Node.js versions or PostgreSQL features.","severity":"breaking","affected_versions":"0.1.0"},{"fix":"Always ensure the `dbConfig` object contains all necessary and correctly typed properties (`host`, `port`, `database`, `username`, `password`) before passing it to `pgUrl`. Implement your own input validation if needed.","message":"The library performs minimal validation on the input `dbConfig` object. Supplying incomplete or malformed parameters (e.g., missing `database` or `username`, or `port` as a non-numeric string) will result in a syntactically malformed connection string, which will then cause connection errors when used by a PostgreSQL client.","severity":"gotcha","affected_versions":"0.1.0"},{"fix":"Always use secure practices for handling database credentials. Retrieve sensitive data from environment variables (as shown in quickstart), a dedicated secret management service, or a secure configuration system. Avoid hardcoding credentials.","message":"Sensitive information like passwords provided in the `dbConfig` object are directly embedded into the connection string. Without proper handling (e.g., environment variables, secret management), this could expose credentials if the connection string is logged or exposed.","severity":"gotcha","affected_versions":"0.1.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure that the `dbConfig` object passed to `pgUrl` includes at least `database` and `username`. Verify that `host` and `port` are correctly specified if not using defaults.","cause":"The generated connection string is missing critical components (e.g., database name, username) or has improperly formatted values due to incomplete input `dbConfig`.","error":"Error: Invalid connection string"},{"fix":"Use the CommonJS `require` syntax: `const pgUrl = require('pg-database-url')`.","cause":"Attempting to use ES module `import` syntax or destructuring assignment with this CommonJS-only package, which exports a single default function.","error":"TypeError: pgUrl is not a function"},{"fix":"Double-check the `password` and `username` properties in your `dbConfig` object to ensure they match the credentials configured for your PostgreSQL database. Ensure no accidental URL encoding issues are present if the password contains special characters, though this library doesn't explicitly mention handling it, modern drivers typically do.","cause":"The generated connection string contains an incorrect password (or username) which is then used by the PostgreSQL client to attempt authentication.","error":"Error: password authentication failed for user \"user\""}],"ecosystem":"npm"}