Connect to Postgres and Run the App
Connect to Postgres and Run the App
Create a database
Using a local Postgres install, or a free hosted instance (Neon, Supabase,
Railway all work), create a database for this project:
createdb contactbook
If you’re using a hosted provider, create the database through their
dashboard instead and grab the connection string they give you.
Configure the connection
In the starter project, copy the example environment file:
cp .env.example .env.local
Open .env.local and set DATABASE_URL to your connection string:
DATABASE_URL=postgres://postgres:postgres@localhost:5432/contactbook
If your hosted provider requires SSL, the connection string usually needs
?sslmode=require on the end. We’ll handle that automatically once we
write the database connection code in Module 2 — for now, just get the
string into .env.local.
Install dependencies and apply the schema
npm install
npm run db:init
db:init runs db/init.js, which reads db/schema.sql and executes it
against DATABASE_URL. Right now that just creates one table:
CREATE TABLE IF NOT EXISTS contacts (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT NOT NULL,
phone TEXT,
email TEXT,
company TEXT,
notes TEXT,
favorite BOOLEAN NOT NULL DEFAULT FALSE,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
You’ll extend this file yourself later, in the Groups module.
Start the dev server
npm run dev
Visit http://localhost:3000.
Checkpoint
You should see the “Contact Book” nav bar, fully styled, with working links
to Home, Favorites, Groups, and Settings. Each page shows a styled
placeholder box naming the module that will implement it. If a page
crashes instead of showing the placeholder, double-check DATABASE_URL in
.env.local — npm run db:init needs a reachable database, even though
the pages themselves don’t query it yet.