Registry / database / parse-database-url

parse-database-url

JSON →
library0.3.0jsnpmunverified

The `parse-database-url` package is a utility designed to parse database connection strings provided as URLs, commonly found in environment variables like `DATABASE_URL` in Heroku deployments. The latest and only version, 0.3.0, was published over 10 years ago (in 2016) and targets very old Node.js versions (0.6, 0.8, 0.10). It is unmaintained and lacks support for modern JavaScript features like ES Modules (ESM) and TypeScript. While it served a purpose in its time by simplifying database configuration from a single URL string, contemporary projects should favor actively maintained alternatives that offer broader database support, robust URL parsing (including special characters in passwords), and modern module compatibility.

npm install parse-database-url
INSTALL
IMPORT
SIG · PARSE-DATABASE-URL
P
parse-database-url
databasejavascriptv0.3.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parseDbUrl
const parseDbUrl = require('parse-database-url');
import parseDbUrl from 'parse-database-url';
This package is CommonJS (CJS) only and was last updated in 2016. It does not support ES Modules (ESM) syntax. Attempting to `import` it will result in a runtime error in ESM contexts.

Demonstrates how to import the package using CommonJS `require` and parse a `DATABASE_URL` string from `process.env`.

const parseDbUrl = require('parse-database-url'); // Example DATABASE_URL, typically from environment variables // For demonstration, using a placeholder. In production, use process.env.DATABASE_URL. process.env.DATABASE_URL = process.env.DATABASE_URL ?? 'postgres://user:password@host:5432/database?sslmode=require'; const dbConfig = parseDbUrl(process.env.DATABASE_URL); console.log('Parsed DB Config:'); console.log(` Driver: ${dbConfig.driver}`); console.log(` Host: ${dbConfig.host}`); console.log(` Port: ${dbConfig.port}`); console.log(` User: ${dbConfig.user}`); console.log(` Database: ${dbConfig.database}`); console.log(` Query Parameters: ${JSON.stringify(dbConfig.query)}`); /* Example Output: Parsed DB Config: Driver: postgres Host: host Port: 5432 User: user Database: database Query Parameters: {"sslmode":"require"} */
Debug
Known issues
breakingThis package is CommonJS (CJS) only. It does not provide ES Module (ESM) exports and cannot be directly imported using `import` statements in Node.js ESM projects.
fix
Use `require()` for importing in CJS environments. For ESM environments, consider using dynamic `import()` or migrating to a modern, actively maintained database URL parser that supports ESM.
affects: >=0.3.0
gotchaThe package is abandoned, with its last update over 10 years ago. It was designed for Node.js versions 0.6-0.10 and is unlikely to be compatible with modern Node.js features, best practices, or security considerations.
fix
It is strongly recommended to use actively maintained alternatives such as `pg-connection-string`, `parse-db-url`, or similar modern libraries that provide up-to-date compatibility and support.
affects: >=0.3.0
gotchaThe package does not ship with TypeScript type definitions. Using it in a TypeScript project will result in 'implicit any' errors or require manual type declarations.
fix
Install `@types/parse-database-url` if available (unlikely for an abandoned package) or create a custom `d.ts` declaration file. The best fix is to migrate to a type-safe alternative.
affects: >=0.3.0
gotchaThere are known issues where the parser may not correctly handle database passwords containing special characters, leading to inconsistent parsing results or connection failures.
fix
Sanitize or properly encode special characters in database URLs if absolutely necessary to use this package, but preferably migrate to a robust parser designed to handle complex URL components securely.
affects: >=0.3.0
gotchaThe library does not validate whether a specified database driver exists or is valid. It will simply parse the string without ensuring the 'driver' field corresponds to a usable database system.
fix
Implement explicit validation logic in your application code for the `driver` field or use an alternative parser that integrates with known database drivers for validation.
affects: >=0.3.0
Errors
Common errors & fixes
TypeError: parseDbUrl is not a function
Attempting to use `parseDbUrl` after an `import` statement in an ESM context, where `require` is expected for this CJS-only package. Or trying to call it with `new`.
fix
Ensure you are using `const parseDbUrl = require('parse-database-url');` in a CommonJS module. If in an ESM module, consider dynamic import: `const parseDbUrl = (await import('parse-database-url')).default;` or, preferably, switch to a modern, ESM-compatible library.
Error [ERR_REQUIRE_ESM]: require() of ES Module ... from ... not supported.
You are attempting to use `require()` within an ES Module (ESM) context to import this CommonJS (CJS) package, which is not directly supported by Node.js.
fix
Either convert your module to CommonJS by removing `"type": "module"` from `package.json` or changing the file extension to `.cjs`, or use a dynamic import: `const parseDbUrl = (await import('parse-database-url')).default;`. It is highly recommended to migrate to a modern, ESM-native library.
Property 'driver' does not exist on type '{}'
This TypeScript error occurs because `parse-database-url` does not provide type definitions, causing TypeScript to infer `parseDbUrl`'s return type as a generic object or `any`.
fix
You will need to manually assert the type (e.g., `parseDbUrl(url) as any`) or declare a custom interface for the parsed database configuration. For robust type-safety, consider migrating to a library that ships with TypeScript declarations.
Upgrade
Version history
0.3.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
parse-database-url — npm install parse-database-url · libregistry