Registry / storage / redis-url-parse

redis-url-parse

JSON →
library2.0.0jsnpmunverified

Parses a Redis URL string into a configuration object with host, port, database, and password fields. Current stable version is 2.0.0. Releases are infrequent; last update was in 2024. Key differentiators: zero dependencies, simple functional API, handles edge cases like URI-encoded passwords and ignored usernames. Alternative to unmaintained packages like parse-redis-url, redis-url, and redis-url-parser.

npm install redis-url-parse
INSTALL
IMPORT
SIG · REDIS-URL-PARSE
R
redis-url-parse
storagejavascriptv2.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

redisUrlParse
const redisUrlParse = require('redis-url-parse')
import redisUrlParse from 'redis-url-parse'
CommonJS only; no ES module support.
default import (ESM)
import redisUrlParse from 'redis-url-parse'
import { redisUrlParse } from 'redis-url-parse'
ESM import works if using Node >=12 with --experimental-modules or bundler, but package does not export named symbol.
type import (TypeScript)
import redisUrlParse from 'redis-url-parse'
import { RedisUrlParse } from 'redis-url-parse'
No TypeScript types shipped; use @types/redis-url-parse or declare module.

Parses a Redis URL string and logs the configuration object with host, port, database, and password.

const redisUrlParse = require('redis-url-parse'); const url = process.env.REDIS_URL ?? 'redis://:password@localhost:6379/0'; const config = redisUrlParse(url); console.log(config.host, config.port, config.database, config.password); // Output: localhost 6379 0 password
Debug
Known issues
gotchaThe package ignores the username part of the URL; only password is extracted.
fix
Do not rely on username field; use password only.
affects: >=1.0.0
gotchaSpecial characters in password must be URI-encoded; otherwise parsing fails or returns wrong password.
fix
Encode password using encodeURIComponent before passing URL.
affects: >=1.0.0
gotchaNo TypeScript types provided; manual type declarations needed.
fix
Create a .d.ts file: declare module 'redis-url-parse';
affects: >=1.0.0
gotchaDatabase is returned as a string, not number; may cause type mismatches.
fix
Parse database with Number() if numeric database index is expected.
affects: >=1.0.0
deprecatedNode.js 6 support was dropped in v2.0.0; older versions may have unpatched vulnerabilities.
fix
Upgrade to v2.0.0 or later, which requires Node >=6.13.0.
affects: <2.0.0
Errors
Common errors & fixes
TypeError: redisUrlParse is not a function
Using named import instead of default import with CommonJS.
fix
Use const redisUrlParse = require('redis-url-parse')
Cannot find module 'redis-url-parse'
Package not installed or wrong import path.
fix
Run npm install redis-url-parse
password property is undefined but URL has password
Password contains special characters not URI-encoded.
fix
URI-encode password: redis://:my%3Asuper%21secure%3Fpassword@host:port/db
database property is a string, expected number
The parser returns database as string.
fix
Convert to number: Number(config.database)
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
32 hits · last 30 days
node
30
Resources
redis-url-parse — npm install redis-url-parse · libregistry