Registry / database / parse-mongo-url

parse-mongo-url

JSON →
library1.1.1jsnpmunverified

Parses MongoDB connection strings into structured objects. Based on the url_parser.js from the MongoDB Node.js native driver v2.0. Version 1.1.1 is stable but has no recent updates (last release in 2017). Lightweight with zero dependencies. Provides a simple API to extract hosts, database name, authentication, and options from MongoDB URIs. Suitable for legacy projects, but for new code consider using the official mongodb driver's built-in parsing or the `mongodb-connection-string-url` package.

npm install parse-mongo-url
INSTALL
IMPORT
SIG · PARSE-MONGO-URL
P
parse-mongo-url
databasejavascriptv1.1.1
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.

default
import parse from 'parse-mongo-url'
const parse = require('parse-mongo-url').default
This package is CJS-only; default import works via synthetic default in TS/ESM. For CJS: const parse = require('parse-mongo-url')
default
const parse = require('parse-mongo-url')
const { parse } = require('parse-mongo-url')
The module exports a single function, not a named export.

Parses a MongoDB connection string and logs the structured result showing hosts, database, auth, and options.

const parse = require('parse-mongo-url'); const uri = 'mongodb://user:pass@localhost:27017/db?replicaSet=rs0'; const parsed = parse(uri); console.log(parsed); // { // hosts: [{ host: 'localhost', port: 27017 }], // database: 'db', // auth: { user: 'user', password: 'pass' }, // options: { replicaSet: 'rs0' } // }
Debug
Known issues
deprecatedPackage is no longer maintained; consider using mongodb-connection-string-url or the official MongoDB driver's parsing.
fix
Replace with import { parse } from 'mongodb-connection-string-url' or use MongoClient's built-in parsing.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: parse is not a function
Using named import { parse } when the module exports a single function as default.
fix
Use const parse = require('parse-mongo-url') (or import parse from 'parse-mongo-url' with ESM).
Cannot find module 'parse-mongo-url' or its corresponding type declarations.
Package does not include TypeScript types. TypeScript projects may need a custom declaration file.
fix
Create a `declare module 'parse-mongo-url'` declaration or use `// @ts-ignore`. Consider switching to mongodb-connection-string-url which has types.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

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