pg-database-url
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/pg-database-url package

0.1.0 • Public • Published

pg-database-url

Build a database url from a config object

NPM

Media Suite

Installation

npm install pg-database-url --save

Usage

var pgUrl = require('pg-database-url')
 
// Example config
// This may already be available from your database configuration or environment variables
var dbConfig = {
  host: 'localhost',
  port: 5432,
  database: 'dbname',
  username: 'user',
  password: 'pass'
}
 
var connString = pgUrl(dbConfig)
// -> 'postgres://user:pass@localhost:5432/dbname'

You can then use the resulting connection string with a library like node-postgres to establish a database connection.

The minimum config object could look look like this:

{
  database: 'dbname',
  username: 'user'
}

which assumes that the connection is on localhost:5432 and the database is configured to not require a password.

This would return a connection string like: 'postgres://user@localhost:5432/dbname'

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.0
    54
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.0
    54

Package Sidebar

Install

npm i pg-database-url

Weekly Downloads

54

Version

0.1.0

License

MIT

Last publish

Collaborators

  • mediasuite