NuxtHub supports multiple deployment environments, each with isolated resources such as databases, KV stores, and buckets. This guide explains how to configure environments across different hosting providers.
| Environment | Purpose | Trigger |
|---|---|---|
| Production | Live application serving end users | Push to main branch |
| Preview | Testing pull requests and feature branches | Push to non-main branches |
| Staging | Pre-production testing environment | Named environment in configuration |
| Local | Development on your machine | Running nuxt dev |
During local development, NuxtHub stores data in the .data/ directory:
| Resource | Local Path |
|---|---|
| SQLite/D1 | .data/db/sqlite.db |
| PostgreSQL | .data/db/ |
| KV | .data/kv/ |
| Blob | .data/blob/ |
| Cache | .data/cache/ |
.data/ directory is included in .gitignore by default in Nuxt projects.To develop against production or preview data, set environment variables that point to your remote resources:
# Connect to a remote Turso database
TURSO_DATABASE_URL=libsql://<your-db>.turso.io
TURSO_AUTH_TOKEN=<your-token>
# Or connect to a remote PostgreSQL database
POSTGRES_URL=postgresql://<user>:<password>@<host>/<database>
Nitro runs Cloudflare's local dev emulation when you use the cloudflare_module preset. This replaces NuxtHub's default local storage and requires a wrangler.jsonc with bindings:
{
"$schema": "node_modules/wrangler/config-schema.json",
"d1_databases": [{ "binding": "DB" }],
"kv_namespaces": [{ "binding": "KV" }, { "binding": "CACHE" }],
"r2_buckets": [{ "binding": "BLOB" }]
}
R2 binding "BLOB" not found or D1 binding "DB" not found.nitro.preset: 'cloudflare_module' in your nuxt.config.ts.Cloudflare Workers supports named environments for managing staging, preview, and other deployment targets.
Define environment-specific bindings in your wrangler.jsonc file:
{
"$schema": "node_modules/wrangler/config-schema.json",
// Production configuration (default)
"d1_databases": [
{ "binding": "DB", "database_id": "<production-db-id>" }
],
"kv_namespaces": [
{ "binding": "KV", "id": "<production-kv-id>" }
],
"r2_buckets": [
{ "binding": "BLOB", "bucket_name": "<production-bucket>" }
],
// Named environments
"env": {
"preview": {
"d1_databases": [
{ "binding": "DB", "database_id": "<preview-db-id>" }
],
"kv_namespaces": [
{ "binding": "KV", "id": "<preview-kv-id>" }
],
"r2_buckets": [
{ "binding": "BLOB", "bucket_name": "<preview-bucket>" }
]
},
"staging": {
"d1_databases": [
{ "binding": "DB", "database_id": "<staging-db-id>" }
],
"kv_namespaces": [
{ "binding": "KV", "id": "<staging-kv-id>" }
],
"r2_buckets": [
{ "binding": "BLOB", "bucket_name": "<staging-bucket>" }
]
}
}
}
d1_databases, kv_namespaces, r2_buckets, vars, durable_objects, and services properties are non-inheritable. You must specify them explicitly in each environment configuration.Set the CLOUDFLARE_ENV environment variable during the build process:
# Deploy to the preview environment
CLOUDFLARE_ENV=preview nuxt build
# Deploy to the staging environment
CLOUDFLARE_ENV=staging nuxt build
CLOUDFLARE_ENV is empty or unset, the default production environment is used.Create separate resources for each environment using the Wrangler CLI:
D1 Databases:
wrangler d1 create my-app-production
wrangler d1 create my-app-preview
wrangler d1 create my-app-staging
KV Namespaces:
wrangler kv namespace create KV
wrangler kv namespace create KV --env preview
wrangler kv namespace create KV --env staging
R2 Buckets:
wrangler r2 bucket create my-app-production
wrangler r2 bucket create my-app-preview
wrangler r2 bucket create my-app-staging
Vercel automatically manages environments based on branch and deployment type.
Configure environment variables in the Vercel dashboard under Project Settings → Environment Variables:
| Variable | Production | Preview | Development |
|---|---|---|---|
DATABASE_URL | Production connection | Preview connection | Local connection |
BLOB_READ_WRITE_TOKEN | Production token | Preview token | Development token |
For preview deployments, you can configure variables that apply only to specific branches:
Vercel handles CI/CD automatically when you connect your repository. Every push triggers a deployment: