The `dsn-parser` package (currently at version 1.0.3) provides a fluent API for parsing and constructing database connection strings (DSNs). It supports common DSN formats, extracting components such as driver, user, password, host, port, database name, and query parameters. A primary use case demonstrated is parsing Heroku-style PostgreSQL environment variables (`pgsql://user:pass@host:port/database`) into an object format compatible with popular database drivers like `node-postgres`. The library can also be used to programmatically build DSNs from individual components, offering a concise way to manage database connection configurations. It is a focused utility library solely for DSN manipulation.
npm install dsn-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates parsing a database connection string from an environment variable and extracting its components for use with a client like `node-postgres`, then building a new DSN programmatically.
Ensure you use `const DSNParser = require('dsn-parser');` when working in a CommonJS environment. In an ESM environment, you might need `import DSNParser from 'dsn-parser';` which relies on Node.js's CJS interop, but direct named imports will fail.Evaluate if the existing functionality meets your current and future needs. For actively evolving database ecosystems or stricter security requirements, consider a more actively maintained alternative if available.
If in a CommonJS file, use `const DSNParser = require('dsn-parser');`. If in an ES module file, use `import DSNParser from 'dsn-parser';` and verify your build setup correctly handles CommonJS interop.Change the import statement to `import DSNParser from 'dsn-parser';` to use ES module syntax. Ensure your environment or bundler is configured to correctly handle CommonJS modules within an ESM project.
No dependency data recorded yet.