{"id":16478,"library":"parse-db-uri","title":"Parse Database URIs","description":"parse-db-uri is a utility library designed to parse database connection URIs into a structured JavaScript object. It extends the output of the 'parse-url' package with database-specific fields such as `database`, `user`, `host`, `password`, and `dialect`. The library is currently stable at version 2.1.2, with recent updates including automatic decoding of passwords and usernames in the URI and added support for SQLite URIs. It provides a straightforward, function-based API for extracting components from common database URI formats, making it easier to configure database connections in applications. The release cadence is irregular but has seen active maintenance recently within the 2.x major version.","status":"active","version":"2.1.2","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/IonicaBizau/parse-db-uri","tags":["javascript","parse","db","uri","database","uris"],"install":[{"cmd":"npm install parse-db-uri","lang":"bash","label":"npm"},{"cmd":"yarn add parse-db-uri","lang":"bash","label":"yarn"},{"cmd":"pnpm add parse-db-uri","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package primarily uses CommonJS `module.exports = function` pattern, which translates to a default import in ESM. Using named destructuring for ESM imports will result in `undefined`.","wrong":"import { parseDbUri } from 'parse-db-uri';","symbol":"parseDbUri","correct":"import parseDbUri from 'parse-db-uri';"},{"note":"This is the recommended and most robust way to import the function in Node.js CommonJS environments. Attempting to use named destructuring for `require` will result in `undefined`.","wrong":"const { parseDbUri } = require('parse-db-uri');","symbol":"parseDbUri","correct":"const parseDbUri = require('parse-db-uri');"}],"quickstart":{"code":"const parseDbUri = require(\"parse-db-uri\");\n\nconst mysqlUri = \"mysql://root:secretpass@localhost:3306/my_database\";\nconst sqliteUri = \"sqlite://data/db.sqlite3\";\nconst postgresUri = `postgres://${process.env.DB_USER ?? 'admin'}:${process.env.DB_PASSWORD ?? 'password'}@db.example.com:5432/my_app_db?sslmode=require`;\n\nconsole.log(\"MySQL URI parsed:\", parseDbUri(mysqlUri));\n// Expected output for mysqlUri:\n// { protocols: [ 'mysql' ], protocol: 'mysql', port: 3306, resource: 'localhost', host: 'localhost', user: 'root', password: 'secretpass', pathname: '/my_database', hash: '', search: '', href: 'mysql://root:secretpass@localhost:3306/my_database', query: {}, parse_failed: false, uri: 'mysql://root:secretpass@localhost:3306/my_database', database: 'my_database', dialect: 'mysql' }\n\nconsole.log(\"SQLite URI parsed:\", parseDbUri(sqliteUri));\n// Expected output for sqliteUri:\n// { protocols: [ 'sqlite' ], protocol: 'sqlite', port: 0, resource: 'data', host: 'data', user: '', password: '', pathname: 'data/db.sqlite3', hash: '', search: '', href: 'sqlite://data/db.sqlite3', query: {}, parse_failed: false, uri: 'sqlite://data/db.sqlite3', dialect: 'sqlite' }\n\nconsole.log(\"PostgreSQL URI parsed:\", parseDbUri(postgresUri));","lang":"javascript","description":"Demonstrates parsing MySQL, SQLite, and PostgreSQL database URIs into structured objects, including database-specific fields and environment variable usage for sensitive credentials."},"warnings":[{"fix":"Carefully review the package's behavior and the structure of the returned object if upgrading from a 1.x version. Consult the `parse-url` documentation for any upstream changes.","message":"Version 2.0.0 introduced a major version bump, implying potential breaking changes. While specific details were not provided in the changelog, users upgrading from 1.x should exercise caution and thoroughly test their implementations, as underlying parsing logic or result object structure may have changed.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"For ESM projects, always use `import parseDbUri from 'parse-db-uri';`. For CommonJS, use `const parseDbUri = require('parse-db-uri');`.","message":"The package is primarily a CommonJS module that exports a single function as its default. In modern ESM environments, attempting to use named imports (`import { parseDbUri } from 'parse-db-uri';`) will fail, returning `undefined` for `parseDbUri`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"No specific fix is required, but be mindful that the `user` and `password` fields in the parsed object will contain their decoded values. Adjust any downstream logic that might expect encoded characters.","message":"As of version 2.1.2, the library automatically decodes URL-encoded characters within usernames and passwords. While this is generally desired for usability, developers should be aware of this behavior, especially if their application relies on the raw, encoded form of these URI components.","severity":"gotcha","affected_versions":">=2.1.2"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure the import statement is `import parseDbUri from 'parse-db-uri';` for ESM, or `const parseDbUri = require('parse-db-uri');` for CommonJS.","cause":"This error typically occurs when the `parseDbUri` function is not correctly imported or referenced, often due to an incorrect import syntax for a default export (e.g., using named destructuring for a CommonJS default).","error":"TypeError: parseDbUri is not a function"},{"fix":"Verify that `import parseDbUri from 'parse-db-uri';` or `const parseDbUri = require('parse-db-uri');` is present at the top of your module and that `parseDbUri` is spelled correctly wherever it's used.","cause":"The variable `parseDbUri` was used before it was declared or properly imported into the current scope, or there's a typo in the variable name.","error":"ReferenceError: parseDbUri is not defined"}],"ecosystem":"npm"}