Skip to main content

Environment Verification Script Setup

This guide shows how to add the environment verification script to each Factory app.

Quick Setup

1. Copy the script to your app

2. Add npm scripts to package.json

3. Add .dev.vars.example to your app

Then create .dev.vars by copying and filling in the template:

4. Test the verification

What the Script Does

Checks for Local Development (npm run verify:env)

  1. βœ… wrangler.jsonc exists
  2. βœ… src/env.ts exists
  3. βœ… src/index.ts exists
  4. βœ… .dev.vars exists and has values (not empty)
  5. βœ… Worker name doesn’t contain β€œ-staging” (local naming)
  6. βœ… Hyperdrive binding configured (DB)
  7. βœ… Rate limiter binding configured (AUTH_RATE_LIMITER)
  8. βœ… /health endpoint defined in src/index.ts
  9. βœ… All required environment fields declared in src/env.ts
  10. βœ… All required values set in .dev.vars

Checks for Staging (npm run verify:env:staging)

Same as local, plus:
  • βœ… Worker name contains β€œ-staging”

Checks for Production (npm run verify:env:production)

Same as local, but:
  • βœ… Worker name does NOT contain β€œ-staging”

Usage Examples

Before Starting Local Dev

Before Deploying to Staging

Before Deploying to Production

Integrated into Dev Startup

Edit package.json:
Now running npm run dev always verifies environment first:

Script Output Examples

Success

Failure

Customizing the Script

The script is highly customizable. Edit scripts/verify-env.js:

Add a New Check

Skip a Check for Your App

Change Environment Names

See Also