The recommended way to connect to postgres is via the client node-postgres. Install it by running npm install pg.

Basic example

Put the code in a file and name it elephantsql.js You run the code by typing the following in terminal:
node filename.js
var pg = require('pg');
//or native libpq bindings
//var pg = require('pg').native

var conString = "INSERT_YOUR_POSTGRES_URL_HERE" //Can be found in the Details page
var client = new pg.Client(conString);
client.connect(function(err) {
  if(err) {
    return console.error('could not connect to postgres', err);
  client.query('SELECT NOW() AS "theTime"', function(err, result) {
    if(err) {
      return console.error('error running query', err);
    // >> output: 2018-08-23T14:02:57.117Z