Cloudflare Workers

Learn how to deploy your app to Cloudflare Workers.

Setup

  1. Sign up / Log in to Cloudflare.
  2. Set up Hyperdrive (for database connections):
    • In the Cloudflare dashboard, go to Storage & Databases → Hyperdrive.
    • Click Create Hyperdrive and connect it to your database (e.g., Postgres, MySQL).
    • Once created, copy the Hyperdrive ID.
    • Run the following command in your project
      Terminal
      mv wrangler.example.toml wrangler.toml
      
    • Set it to wrangler.toml:
      wrangler.toml
      [[hyperdrive]]
      binding = "HYPERDRIVE"
      id = "your-hyperdrive-id"
      
  3. Set nitro preset in environment variable:
    .env
    NITRO_PRESET="cloudflare_module"
    
  4. Commit changes and push to your repository.
  5. Deploy via Cloudflare:
    • Go to Workers & Pages → Create Application → Create Worker.
    • Connect your GitHub repository.
    • Set the build command to: npm run build
    • Add environment variables (.env.local values).
    • Click Deploy to build and launch
  6. Access and verify your live site at the Cloudflare Workers URL.
  7. Auto-deploy happens on every push to the main branch.
  8. Check logs in Cloudflare dashboard if something fails during build or runtime.