Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

parse-database-url

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-database-url - npm Package Compare versions

Comparing version 0.2.2 to 0.3.0

.travis.yml

38

lib/parse-database-url.js
var url = require("url");
var querystring = require("querystring");
var mongodbUri = require("mongodb-uri");
/**

@@ -20,4 +22,4 @@ * This is the exported function that parses database URLs.

config.driver = (parsedUrl.protocol || "sqlite3:")
// The protocol coming from url.parse() has a trailing :
.replace(/\:$/, "")
// The protocol coming from url.parse() has a trailing :
.replace(/\:$/, "");

@@ -31,3 +33,3 @@ // Cloud Foundry will sometimes set a 'mysql2' scheme instead of 'mysql'.

if (parsedUrl.auth) {
var userPassword = parsedUrl.auth.split(':', 2);
var userPassword = parsedUrl.auth.split(":", 2);
config.user = userPassword[0];

@@ -53,6 +55,28 @@ if (userPassword.length > 1) {

} else {
// Some drivers (e.g., redis) don't have database names.
if (parsedUrl.pathname) {
config.database =
parsedUrl.pathname.replace(/^\//, "").replace(/\/$/, "");
if (config.driver === "mongodb") {
// MongoDB URLs can have multiple comma-separated host:port pairs. This
// trips up the standard URL parser.
var mongoParsedUrl = mongodbUri.parse(databaseUrl);
parsedUrl = {};
if (mongoParsedUrl.hosts) {
config.hosts = mongoParsedUrl.hosts;
for (var i = 0; i < config.hosts.length; i += 1) {
if (config.hosts[i].port)
config.hosts[i].port = config.hosts[i].port.toString();
}
if (config.hosts.length === 1) {
if (config.hosts[0].host)
config.host = config.hosts[0].host;
if (config.hosts[0].port)
config.port = config.hosts[0].port.toString();
}
}
if (mongoParsedUrl.database)
config.database = mongoParsedUrl.database;
} else {
// Some drivers (e.g., redis) don't have database names.
if (parsedUrl.pathname) {
config.database =
parsedUrl.pathname.replace(/^\//, "").replace(/\/$/, "");
}
}

@@ -59,0 +83,0 @@

7

package.json
{
"name": "parse-database-url",
"version": "0.2.2",
"version": "0.3.0",
"description": "Database configuration URL parser for node.js",

@@ -20,6 +20,7 @@ "keywords": ["database", "configuration", "url", "heroku", "database_url"],

"dependencies": {
"mongodb-uri": ">= 0.9.7"
},
"devDependencies": {
"chai": ">= 1.6.0",
"mocha": ">= 1.10.0"
"chai": ">= 3.4.1",
"mocha": ">= 2.3.4"
},

@@ -26,0 +27,0 @@ "main": "lib/parse-database-url.js",

# DATABASE_URL parser for node.js
[![Build Status](https://travis-ci.org/pwnall/node-parse-database-url.svg)](https://travis-ci.org/pwnall/node-parse-database-url)
[![NPM Version](http://img.shields.io/npm/v/parse-database-url.svg)](https://www.npmjs.org/package/parse-database-url)
This is an [npm](https://npmjs.org/) package that parses database

@@ -4,0 +7,0 @@ configurations passed in as URLs. This is typically useful in Heroku

@@ -92,3 +92,60 @@ [

}
},
{
"desc": "MongoDB URL with username and host",
"url": "mongodb://someuser@server.heroku.com/herokudb",
"config": {
"driver": "mongodb",
"user": "someuser",
"host": "server.heroku.com",
"hosts": [
{
"host": "server.heroku.com"
}
],
"database": "herokudb"
}
},
{
"desc": "MongoDB URL with username/password and host/port",
"url": "mongodb://user:pass@server.heroku.com:1337/herokudb",
"config": {
"driver": "mongodb",
"user": "user",
"password": "pass",
"host": "server.heroku.com",
"port": "1337",
"hosts": [
{
"host": "server.heroku.com",
"port": "1337"
}
],
"database": "herokudb"
}
},
{
"desc": "MongoDB URL with username/password and multiple hosts/ports (Issue #6)",
"url": "mongodb://user:pass@server1.heroku.com:1337,server2.heroku.com:1338,server3.heroku.com:1339/herokudb",
"config": {
"driver": "mongodb",
"user": "user",
"password": "pass",
"hosts": [
{
"host": "server1.heroku.com",
"port": "1337"
},
{
"host": "server2.heroku.com",
"port": "1338"
},
{
"host": "server3.heroku.com",
"port": "1339"
}
],
"database": "herokudb"
}
}
]
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc