Connect To PostgreSQL
suggest changeUse the pg npm module. Install it with npm:
npm install pg --save
Create a PostgreSQL client, which you can query later.
This example assumes the database name is students, the host is localhost, and the user is postgres. The URL scheme is postgres://, not pg://.
var pg = require("pg")
var connectionString = "postgres://postgres:postgres@localhost:5432/students";
var client = new pg.Client(connectionString);
client.connect(function (err) {
if (err) throw err;
});
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents