This guide explains how to set up your development and production environments for the MeshHook project.
The project uses two separate environment configurations:
.env.local- Local development (committed to GitHub).env- Production (NOT committed, in.gitignore)
- Node.js v20 or newer
- pnpm package manager
- Supabase CLI
-
Clone the repository
git clone <repository-url> cd meshhook
-
Install dependencies
pnpm install
-
Run the interactive setup
pnpm run setup
Select "Local Development" when prompted. This will:
- Prompt you for local configuration (or use defaults)
- Create
.env.localwith your settings - Create a symlink from
.envto.env.local
OR use the pre-configured
.env.local:The
.env.localfile is already committed with local Supabase defaults:- Local PostgreSQL:
postgresql://postgres:[email protected]:54322/postgres - Local Supabase API:
http://127.0.0.1:54321 - Default anon and service role keys for local development
- Default port: 8080
-
Start Supabase locally
pnpx supabase start
This will start:
- PostgreSQL database on port 54322
- Supabase API on port 54321
- Supabase Studio on port 54323
-
Run migrations
pnpm run db:migrate
-
Start the application
pnpm run dev
- A Supabase project (create at supabase.com)
- Production server or hosting platform
-
Run the interactive setup
pnpm run setup
Select "Production" (or "Staging") when prompted. This will:
- Prompt you for your Supabase project credentials
- Create
.env.production(or.env.staging) with your settings - Create a symlink from
.envto the selected environment file - Display security reminders
OR manually configure:
-
Manual configuration (alternative)
Copy the template:
cp .env.example .env.production
Edit
.env.productionand replace placeholders with your actual Supabase project values. Default port is 8080 (can be overridden with PORT environment variable). -
Find your Supabase credentials
In your Supabase project dashboard:
- Go to Settings → API
- Copy the Project URL (SUPABASE_URL)
- Copy the anon/public key (SUPABASE_ANON_KEY)
- Copy the service_role key (SUPABASE_SERVICE_ROLE_KEY)
For DATABASE_URL:
- Go to Settings → Database
- Copy the Connection string (URI format)
-
Deploy migrations
pnpm run db:migrate
The script automatically detects your environment from the
.envsymlink. -
Deploy your application
Follow your hosting platform's deployment instructions.
| Variable | Description | Local Default | Production |
|---|---|---|---|
DATABASE_URL |
PostgreSQL connection string | postgresql://postgres:[email protected]:54322/postgres |
Your Supabase DB URL |
SUPABASE_URL |
Supabase API URL | http://127.0.0.1:54321 |
Your project URL |
SUPABASE_ANON_KEY |
Public/anonymous key | Local default key | Your project anon key |
SUPABASE_SERVICE_ROLE_KEY |
Service role key (admin) | Local default key | Your project service key |
PORT |
Application port | 8080 |
8080 (configurable) |
| Variable | Description | Default |
|---|---|---|
NODE_ENV |
Environment mode | development / staging / production |
# Interactive environment setup (local/staging/production)
pnpm run setupThis unified command will:
- Prompt you to select an environment (Local, Staging, or Production)
- Guide you through configuration for the selected environment
- Create the appropriate
.env.*file - Create a symlink from
.envto your selected environment file
# Run migrations (auto-detects environment from .env symlink)
pnpm run db:migrateThis unified command will:
- Detect your current environment from the
.envsymlink - For local: Run
pnpx supabase db reset(resets and re-runs all migrations) - For staging/production: Run
pnpx supabase db push(pushes new migrations)
# Start local Supabase
pnpx supabase start
# Stop local Supabase
pnpx supabase stop
# Reset database (drops all data and re-runs migrations)
pnpx supabase db reset
# Or use: pnpm run db:migrate (when .env points to .env.local)
# Create a new migration
pnpx supabase migration new <migration_name>
# Note: This command will hang - just kill it (Ctrl+C). The file will be created.
# View migration status
pnpx supabase migration list# Link to your Supabase project
pnpx supabase link --project-ref <your-project-ref>
# Push migrations to production
pnpx supabase db push
# Or use: pnpm run db:migrate (when .env points to .env.production)
# Pull remote schema changes
pnpx supabase db pullLocal:
- Ensure Supabase is running:
pnpx supabase status - Check if port 54322 is available
- Restart Supabase:
pnpx supabase stop && pnpx supabase start
Production:
- Verify your
.envfile has correct credentials - Check if your IP is whitelisted in Supabase dashboard
- Ensure DATABASE_URL includes the correct password
- Ensure you're in the project root directory
- Check file names:
.env.localfor development,.envfor production - Verify
.envis in.gitignore(production only) - Restart your application after changing environment variables
- Never modify existing migration files
- Always create new migrations:
pnpx supabase migration new <name> - If you have conflicts, reset local DB:
pnpx supabase db reset
-
Never commit production secrets to version control
.envand.env.productionare in.gitignoreby default- These files contain production secrets
-
.env.localis safe to commit- Contains only local development defaults
- No production secrets
- Committed to repo for easy team setup
-
Use the setup script
pnpm run setupfor any environment- Select your target environment when prompted
- Script creates proper symlinks automatically
-
Rotate keys regularly
- Especially if accidentally exposed
- Can be done in Supabase dashboard
-
Use service role key carefully
- Has admin privileges
- Only use server-side
- Never expose to client