Skip to content

Instantly share code, notes, and snippets.

@kharandziuk
Created February 15, 2017 21:36
Show Gist options
  • Save kharandziuk/53b26452b38b78c39c751dac20355cd5 to your computer and use it in GitHub Desktop.
Save kharandziuk/53b26452b38b78c39c751dac20355cd5 to your computer and use it in GitHub Desktop.
var pg = require('pg');
var client = new pg.Client();
// connect to our database
client.connect(function (err) {
if (err) throw err;
// execute a query on our database
client.query('SELECT COUNT(*) FROM Hotels;', function (err, result) {
if (err) throw err;
console.log(result.rows[0]);
client.end(function (err) {
if (err) throw err;
});
});
});
// call it like this: PGUSER=booking PGPASSWORD=booking PGHOST=localhost PGPORT=15432 PGDATABASE=booking node connect.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment