pg-database-url
v0.1.0
Published
Build a database url from a config object
Downloads
379
Maintainers
Readme
pg-database-url
Build a database url from a config object
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'