
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeGreat questions! Let me help you with both of these.
Actually, there's a common misconception here: your frontend application doesn't connect to your Studio - it connects directly to Sanity's Content Lake (the hosted API). Whether your Studio is running locally or deployed doesn't affect where your frontend fetches data from.
What you actually want to configure is which dataset your frontend uses. You can set up different datasets for development and production, then use environment variables to control which one your app connects to.
Here's how to set this up:
In your frontend application (e.g., Next.js), create environment files:
.env.local (for local development):
NEXT_PUBLIC_SANITY_PROJECT_ID=your-project-id NEXT_PUBLIC_SANITY_DATASET=development
.env.production:
NEXT_PUBLIC_SANITY_PROJECT_ID=your-project-id NEXT_PUBLIC_SANITY_DATASET=production
Then in your Sanity client configuration:
import { createClient } from '@sanity/client'
export const client = createClient({
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,
apiVersion: '2024-01-01',
useCdn: false, // Use false for development to get fresh data
})In your Studio, you can also use environment-specific configs with .env.development and .env.production files using the SANITY_STUDIO_ prefix as described in the environment variables documentation.
Don't forget to add http://localhost:3000 (or your dev port) to your CORS origins in your project settings!
You'll use the dataset export and import commands for this. Here's the workflow:
Export from your local dataset:
sanity dataset export development ./backup.tar.gzImport to your production dataset:
sanity dataset import backup.tar.gz productionA few important notes:
sanity dataset export production backup-before-import.tar.gzIf you only want to migrate specific documents, you can export to NDJSON format and use GROQ queries to filter what you're exporting, as shown in this ad-hoc migration recipe.
Hope this helps! Let me know if you need clarification on any of these steps.
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store