Registry / database / mongo-url-parser

mongo-url-parser

JSON →
library1.0.2jsnpmunverified

Parses MongoDB connection strings into structured objects with auth, server, database, and replica set options. Version 1.0.2 is stable but no longer actively maintained; the functionality is provided natively by the mongodb driver's MongoClient constructor. For production use, prefer official MongoDB driver's connection string parsing over this standalone package.

npm install mongo-url-parser
INSTALL
IMPORT
SIG · MONGO-URL-PARSER
M
mongo-url-parser
databasejavascriptv1.0.2
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 (function)
import parseUrl from 'mongo-url-parser';
import { parseUrl } from 'mongo-url-parser';
Package exports a single default function. CommonJS require also works.
parser (CommonJS)
const parser = require('mongo-url-parser');
No named export; the default function is assigned to parser.
TypeScript usage
// @ts-ignore import parseUrl from 'mongo-url-parser';
import * as parseUrl from 'mongo-url-parser';
Package has no TypeScript declarations; use disable comment or create a .d.ts.

Parses a MongoDB connection string and logs the structured result object with auth, servers, and options.

import parseUrl from 'mongo-url-parser'; const url = 'mongodb://myDBReader:D1fficultP%40ssw0rd@mongodb0.example.com:27017/?authSource=admin'; const parsed = parseUrl(url); console.log(parsed); // { // usingSrv: false, // auth: { user: 'myDBReader', password: 'D1fficultP@ssw0rd' }, // server_options: { socketOptions: {} }, // db_options: { read_preference_tags: null, authSource: 'admin', read_preference: 'primary' }, // rs_options: { socketOptions: {} }, // mongos_options: {}, // dbName: 'admin', // servers: [ { host: 'mongodb0.example.com', port: 27017 } ] // }
Debug
Known issues
deprecatedPackage is no longer actively maintained. Use official MongoDB driver's connection string parsing instead.
fix
Migrate to `new MongoClient(url)` from 'mongodb' package which parses the URL internally.
affects: >=1.0.0
gotchaSpecial characters in password must be URL-encoded in the connection string; parser decodes them.
fix
Ensure password is URL-encoded (e.g., %40 for @) before passing to parser.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: parser is not a function
Trying to use a named import instead of default import in ESM.
fix
Use `import parseUrl from 'mongo-url-parser'` or `const parser = require('mongo-url-parser')`.
Cannot find module 'mongo-url-parser' or its corresponding type declarations.
Package has no TypeScript declarations; TypeScript strict mode fails.
fix
Add `// @ts-ignore` before import or create a `mongo-url-parser.d.ts` file with `declare module 'mongo-url-parser';`.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

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