Environment Configuration
Configure API keys, secrets, and environment variables for Portfolio OS
Overview
Configure API keys, secrets, and environment variables for Portfolio OS
Portfolio OS uses environment variables to configure API keys, database connections, and feature flags across different environments.
Environment Files Overview
The monorepo uses separate environment files for each app:
| File Location | Purpose | When to Use |
|---|---|---|
apps/site/.env.local | Site app secrets | Development & Production |
apps/dashboard/.env.local | Dashboard app secrets | Development & Production |
apps/site/.env.example | Site environment template | Reference for required variables |
apps/dashboard/.env.example | Dashboard environment template | Reference for required variables |
Note:
Never commit .env.local files to Git! They are automatically ignored via .gitignore to protect sensitive credentials.
Quick Setup
Copy Environment Templates
# From the repository root
cp apps/site/.env.example apps/site/.env.local
cp apps/dashboard/.env.example apps/dashboard/.env.local
Edit Environment Files
Open each .env.local file and fill in your API keys and configuration values.
Start with the required variables (marked below), then add optional ones as needed.
Restart Development Servers
# Stop the dev servers (Ctrl+C) and restart
pnpm dev
Environment variables are loaded at build time for Next.js.
Site App Environment Variables
Configuration for apps/site/.env.local:
Required Variables
Hashnode Content Integration
Portfolio OS can source blog content from Hashnode via their GraphQL API.
NEXT_PUBLIC_HASHNODE_PUBLICATION_HOST=yourblog.hashnode.dev
How to get this:
- Sign up at hashnode.com
- Create a publication
- Use your publication's domain (e.g.,
mindware.hashnode.dev)
Note:
This variable is public (prefixed with NEXT_PUBLIC_) and will be exposed to the browser.
Optional Variables
# Base URL for absolute URLs (useful for OG images, sitemaps)
NEXT_PUBLIC_BASE_URL=http://localhost:3000
# Environment mode
NEXT_PUBLIC_MODE=development
# Feature flags
NEXT_PUBLIC_ENABLE_ANALYTICS=false
NEXT_PUBLIC_ENABLE_COMMENTS=false
Dashboard App Environment Variables
Configuration for apps/dashboard/.env.local:
Required Variables
Database URL (SQLite for Development)
DATABASE_URL=file:./dev.db
Note:
The dashboard uses Prisma with SQLite for local development. In production, you can switch to PostgreSQL or another database.
Blob Storage (Vercel Blob)
BLOB_READ_WRITE_TOKEN=vercel_blob_rw_...
How to get this:
- Create a Vercel account
- Enable Blob Storage for your project
- Copy the read/write token
Optional Variables
# Admin authentication
ADMIN_EMAIL=admin@example.com
ADMIN_PASSWORD_HASH=your-bcrypt-hash
# Analytics
NEXT_PUBLIC_VERCEL_ANALYTICS_ID=your-analytics-id
Complete Environment File Examples
apps/site/.env.local
# Hashnode Content
NEXT_PUBLIC_HASHNODE_PUBLICATION_HOST=mindware.hashnode.dev
# AI Features
OPENAI_API_KEY=sk-proj-your-key-here
# Email
RESEND_API_KEY=re_your-key-here
RESEND_FROM_EMAIL=noreply@yourdomain.com
RESEND_TO_EMAIL=your-email@example.com
# Caching
UPSTASH_REDIS_REST_URL=https://your-redis.upstash.io
UPSTASH_REDIS_REST_TOKEN=your-token-here
# Optional Configuration
NEXT_PUBLIC_BASE_URL=http://localhost:3000
NEXT_PUBLIC_MODE=development
apps/dashboard/.env.local
# Database
DATABASE_URL=file:./dev.db
# Storage
BLOB_READ_WRITE_TOKEN=vercel_blob_rw_your-token-here
# Optional
ADMIN_EMAIL=admin@example.com
Environment Variable Loading
Next.js automatically loads environment variables in this order:
.env.local(highest priority, gitignored).env.developmentor.env.production(based on NODE_ENV).env(lowest priority)
Note:
Variables prefixed with NEXT_PUBLIC_ are exposed to the browser and baked into the JavaScript bundle at build time.
Production Deployment
When deploying to Vercel, Railway, or other platforms:
Add Environment Variables to Platform
Navigate to your project settings and add all required environment variables.
For Vercel:
- Go to Project Settings → Environment Variables
- Add each variable individually
- Select which environments they apply to (Production, Preview, Development)
Update Production-Specific Values
# Change these for production
NEXT_PUBLIC_BASE_URL=https://yourdomain.com
NEXT_PUBLIC_MODE=production
DATABASE_URL=postgresql://user:password@host:5432/dbname
Redeploy Application
Changes to environment variables require a new deployment to take effect.
Security Best Practices
Note:
Critical Security Guidelines:
- Never commit
.env.localfiles to version control - Don't expose server-side API keys in
NEXT_PUBLIC_variables - Rotate API keys if they're accidentally exposed
- Use different API keys for development and production
- Enable rate limiting on production API keys
Checking for Exposed Secrets
# Scan repository for accidentally committed secrets
git log --all --full-history -- "**/.env.local"
# If found, rotate all exposed credentials immediately
Troubleshooting
Environment Variables Not Loading
Problem: Variables are undefined in your app
Solutions:
- Ensure
.env.localfile exists in the correct app directory - Restart development server after adding/changing variables
- Check variable names are spelled correctly
- For client-side access, ensure variable is prefixed with
NEXT_PUBLIC_
Build Errors Due to Missing Variables
Problem: Build fails with "Required environment variable X is not set"
Solutions:
- Check that all required variables are present in
.env.local - Ensure variables are set in your deployment platform
- Verify no typos in variable names
Variables Work Locally But Not in Production
Problem: App works in development but fails in production
Solutions:
- Add environment variables to your hosting platform (Vercel, Railway, etc.)
- Ensure production database URL is correct
- Check that
NEXT_PUBLIC_BASE_URLmatches your production domain
Next Steps
With your environment configured:
- First Steps Tutorial - Build your first feature
- Setup Guides - Configure database and storage
- API Reference - Explore available APIs
Note:
For production deployment configuration, see the Deployment Runbook.