Node.js Connect To PostgreSQL

Example

Using PostgreSQLnpm module.

install dependency from npm

npm  install pg --save

Now you have to create a PostgreSQL connection, which you can later query.

Assume you Database_Name = students, Host = localhost and DB_User= postgres

var pg = require("pg")
var connectionString = "pg://postgres:postgres@localhost:5432/students";
var client = new pg.Client(connectionString);
client.connect();