Node.js, PostgreSQL error: no pg_hba.conf entry for host

Change your connection code to use ssl. Following your linked example:

var conString = "pg://admin:guest@localhost:5432/Employees";
var client = new pg.Client(conString);
client.connect();

becomes:

var client = new pg.Client({
    user: "admin",
    password: "guest",
    database: "Employees",
    port: 5432,
    host: "localhost",
    ssl: true
}); 
client.connect();

https://github.com/brianc/node-postgres/wiki/Client#new-clientobject-config--client


Running on heroku:

We ran into this error while upgrading the pg database on heroku from hobby tier to standard-0. SSL is required, but we didnt set it in our config.

Include in config when initialize new Sequelize(...)

"dialect": "postgres",
"dialectOptions": {
  "ssl": true
}

This trick was, that the ssl option is wrapped in dialectOptions. found here: https://github.com/sequelize/sequelize/issues/956#issuecomment-147745033

Info by @Atish: Use

options: { 
  dialect: "postgres",
  native: true, # adding this maybe breaks on hobby dyno
  ssl: true, 
  dialectOptions: {
    ssl: true
  }
}

In the case sequelize ignores all of your efforts to turn ssl on, you can try to convince pg to enable ssl for all conncetions by default:

var pg = require('pg');
pg.defaults.ssl = true;

const Sequelize = require('sequelize');
const sequelize = new Sequelize('postgres://...');

const sequelize = new Sequelize({
  database: "DB",
  username: "root",
  password: "pass",
  host: "localhost",
  port: 5432,
  dialect: "postgres",
  dialectOptions: {
    ssl: {
      require: true, // This will help you. But you will see nwe error
      rejectUnauthorized: false // This line will fix new error
    }
  },
});