New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pg-connection-from-env

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

pg-connection-from-env

Convert environment variables into a usable postgres connection object or postgres uri

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
181
decreased by-91.44%
Maintainers
1
Weekly downloads
 
Created
Source

pg-connection-from-env

Convert environment variables into a usable postgres connection object or postgres uri

Installation

yarn add pg-connection-from-env

Usage

import getPgConnectionFromEnv, {
  getConnectionStringFromEnv,
} from "pg-connection-from-env"

getPgConnectionFromEnv()
// {
//   host: 'localhost',
//   user: 'postgres',
//   port: 5432,
//   password: '',
//   database: 'postgres',
//   ssl: false
// }

getPgConnectionFromEnv({
  fallbackDefaults: {
    user: "userifenvdoesntprovide",
    database: "databaseifenvdoesntprovide",
  },
})
// {
//  host: 'localhost',
//  user: 'userifenvdoesntprovide',
//  port: 5432,
//  password: '',
//  database: 'databaseifuserdoesntprovide',
//  ssl: false
// }

getConnectionStringFromEnv(/* same args as getPgConnectionFromEnv */)
// "postgresql://postgres:@localhost:5432/postgres"

Arguments

ArgumentDescription
fallbackDefaultsDefaults if env does not provide host, database, user etc.
userOverride user with this
databaseOverride env database with this
envEnvironment object to use instead of process.env

Environment Variables

The following environment variables are used (basically standard postgres env variables)

Var NameDescription
POSTGRES_HOSTPostgres Host
POSTGRES_PASS, POSTGRES_PASSWORDPostgres Password
POSTGRES_DATABASE, POSTGRES_DBPostgres Database
POSTGRES_USER, POSTGRES_USERNAMEPostgres User
POSTGRES_PORTPostgres Port
POSTGRES_URI, POSTGRES_URL, PG_URI, DATABASE_URLPostgres URI postgresql://...
POSTGRES_SSLIf set, true

FAQs

Package last updated on 11 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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