Node.js and PostGres have grown in popularity for several companies to have in their tech stack. Let's do a quick walkthrough on how to setup and write our first query.
We will be using:
Prerequisites:
- Node and npm already installed
- Postgres database setup (Tutorial Here)
Assuming you have the prerequisites. If you haven't you can follow the instructions here. Let's stat by creating a new project. Open Terminal or your CLI tool of choice. I recommend iTerm. Let's create a new project.
mkdir new-project
cd new-project
npm init
You will then be prompted to name the project, license, etc. You can just click "enter" through these.
Next create our server.js
node file and past the following code below.
server.js
require('dotenv');
var knex = require('knex')({
client: 'pg',
connection: {
user: process.env.USER,