Local Development
Learn how to set up your local development environment.
This guide will help you set up your local development environment for the Pro Next.js Drizzle starter kit, including the necessary services like PostgreSQL.
Prerequisites
To run the application locally, you need to have the following:
- Node.js (v18 or later)
- npm (comes with Node.js)
- PostgreSQL (v14 or later)
Setting Up Local Services
Option 1: Local PostgreSQL Installation
Install PostgreSQL on your machine and create a database:
createdb your_database_nameOption 2: Docker Compose (Recommended)
Create a docker-compose.yml file in your project root with the following configuration:
version: '3.8'
services:
postgres:
image: postgres:15-alpine
container_name: pro-nextjs-postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: pro_nextjs
ports:
- '5432:5432'
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U postgres']
interval: 5s
timeout: 5s
retries: 5
volumes:
postgres_data:Starting the Services
- Start the services using Docker Compose:
docker-compose up -d- Verify that the services are running:
docker-compose psEnvironment Configuration
Create or update your .env file with the following configuration:
# Database
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/pro_nextjs"
# Authentication (required)
BETTER_AUTH_SECRET="your-secret-key-here"
# Stripe (optional, for billing features)
STRIPE_SECRET_KEY="sk_test_..."
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY="pk_test_..."
STRIPE_WEBHOOK_SECRET="whsec_..."
# Email (optional, for email features)
RESEND_API_KEY="re_..."
EMAIL_FROM="noreply@example.com"Accessing the Services
- PostgreSQL:
- Host: localhost
- Port: 5432
- Username: postgres
- Password: postgres
- Database: pro_nextjs
Running Database Migrations
After setting up your database, you have two options:
Option 1: Push schema directly (for initial setup)
npm run db:pushOption 2: Generate and apply migrations
npm run db:generate
npm run db:migrateStart Development Server
Start the development server:
npm run devYour application should now be running at http://localhost:3000 with the local PostgreSQL database.
Troubleshooting
Database Connection Issues
If you're having trouble connecting to PostgreSQL:
- Verify the database is running:
docker-compose ps postgres- Check the logs:
docker-compose logs postgres- Verify your
DATABASE_URLin.envmatches your database configuration
Port Already in Use
If port 3000 is already in use, you can change it by setting the PORT environment variable:
PORT=3001 npm run devStopping the Services
To stop all services:
docker-compose downTo stop and remove all data (including volumes):
docker-compose down -v