Skip to content

Instantly share code, notes, and snippets.

@mhkeller
Last active November 3, 2018 04:02
Show Gist options
  • Save mhkeller/c11aa12ea344251d4dd2fadd18a9f7cd to your computer and use it in GitHub Desktop.
Save mhkeller/c11aa12ea344251d4dd2fadd18a9f7cd to your computer and use it in GitHub Desktop.
Basic node-pg connection setup
import { Pool } from 'pg';
export default function db (connectionString) {
const pool = new Pool(connectionString);
pool.on('error', err => {
console.error(err);
});
return pool;
};
{ "connectionString": "postgres://localhost:5432" }
import db from './_db.js';
import connectionString from './connection-string.json';
const pool = db(connectionString);
(async function () {
const result = await pool.query(`SELECT * FROM my_table`);
console.log(result);
}).call();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment