Before doing some more fancy stuff, we should learn how to talk to our PostgreSQL database. In order to do so, once an appropriate project is created, we need to install a DB client. I used node-PostgreSQL:
npm install pg --save
npm is the Node.js package manager, a utility that helps managing node packages: creating them, installing remote package, and so on. You will find more information at https://docs.npmjs.com/.
The code should be created in an index.js file:
const pg = require('pg');
//init client with the appropriate conn details
const client = new pg.Client({
host: 'localhost',
port: 5434,
user: 'postgres',
password: 'postgres',
database: 'mastering_postgis'
});
//connect to the db
client.connect(function(err){
if(err){
console.warn('Error connecting to the database...