Skip to main content

Overview

shrtnr is built with Next.js 16 and requires a PostgreSQL database (Neon) and Redis cache (Upstash) for optimal performance. This guide walks you through the complete deployment process.

Prerequisites

Before deploying, ensure you have:
  • Node.js 20+ installed
  • A Neon account for PostgreSQL
  • An Upstash account for Redis
  • A deployment platform (Vercel, Railway, or similar)

Tech Stack

Next.js 16.1.6

Modern React framework with App Router

Neon PostgreSQL

Serverless PostgreSQL with auto-scaling

Upstash Redis

Serverless Redis for caching and rate limiting

NextAuth v5

Authentication with credentials provider

Dependencies

The application uses the following core dependencies:
package.json
{
  "dependencies": {
    "@neondatabase/serverless": "^0.10.0",
    "@upstash/redis": "^1.36.2",
    "next": "16.1.6",
    "next-auth": "^5.0.0-beta.30",
    "react": "19.2.3",
    "nanoid": "^5.1.6",
    "bcryptjs": "^3.0.3",
    "date-fns": "^4.1.0",
    "lucide-react": "^0.575.0",
    "motion": "^12.34.1"
  }
}

Deployment Steps

1

Clone and Install

Clone the repository and install dependencies:
git clone <your-repo-url>
cd shrtnr
npm install
2

Set Up Neon PostgreSQL

  1. Create a new project at neon.tech
  2. Copy your connection string from the dashboard
  3. The connection string format: postgresql://user:password@host/database?sslmode=require
Neon provides a pooled connection string - use this for serverless environments
3

Set Up Upstash Redis

  1. Create a new Redis database at upstash.com
  2. Copy the REST URL and REST Token from the dashboard
  3. Upstash Redis uses HTTP-based requests, perfect for serverless
4

Configure Environment Variables

Create a .env.local file with your credentials:
.env.local
# Database
POSTGRES_URL="postgresql://user:password@host/database?sslmode=require"

# Redis
UPSTASH_REDIS_REST_URL="https://your-redis.upstash.io"
UPSTASH_REDIS_REST_TOKEN="your-redis-token"

# Authentication
AUTH_SECRET="your-secure-random-string"
NEXTAUTH_URL="http://localhost:3000"
Generate AUTH_SECRET using: openssl rand -base64 32
See Environment Variables for complete reference.
5

Initialize Database

Run the database initialization script:
npm run db:init
This creates all required tables and indexes. See Database Setup for schema details.
6

Test Locally

Run the development server:
npm run dev
Visit http://localhost:3000 to verify everything works.
7

Deploy to Production

# Install Vercel CLI
npm i -g vercel

# Deploy
vercel

# Add environment variables in Vercel dashboard
# Then deploy to production
vercel --prod
Vercel automatically detects Next.js and configures build settings
8

Run Post-Deployment Checks

Verify your deployment:
  • Homepage loads correctly
  • Can create a short link
  • Short links redirect properly
  • User registration works
  • Login authentication functions
  • Analytics are being tracked

Production Checklist

  • AUTH_SECRET is a strong random string (32+ characters)
  • Environment variables are not committed to git
  • HTTPS is enabled on your domain
  • Database connections use SSL
  • Rate limiting is configured in Redis
  • Redis caching is active for link lookups
  • Database indexes are created (handled by migration)
  • Next.js is running in production mode
  • CDN is configured for static assets
  • Error tracking is configured (e.g., Sentry)
  • Uptime monitoring is active
  • Database connection pooling is enabled
  • Log aggregation is set up

Troubleshooting

  1. Verify POSTGRES_URL is correct
  2. Check if Neon project is active
  3. Ensure SSL mode is included: ?sslmode=require
  4. Test connection with: npm run test:db
  1. Verify UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN
  2. Check Upstash dashboard for database status
  3. Ensure REST API is enabled (not just regular Redis protocol)
  1. Verify AUTH_SECRET is set
  2. Set NEXTAUTH_URL to your production domain
  3. Check that trustHost: true is enabled in production
  4. Ensure users table exists in database

Next Steps

Environment Variables

Complete reference for all configuration options

Database Schema

Understand the database structure and migrations

Build docs developers (and LLMs) love