Clarification on using the command `npm create sanity@latest` in a NextJS web app.
You're reading that correctly! The npm create sanity@latest command is indeed designed to initialize a new Sanity Studio project, not specifically to integrate into existing applications. However, you can still use it with your existing Next.js app - let me explain how.
Running the Command in Your Existing Project
When you run this command in an existing Next.js project directory:
npm create sanity@latest
# or
npx sanity@latest initThe CLI will initialize a new Sanity Studio project through an interactive setup that:
- Authenticates you with Sanity (if needed)
- Lets you select or create a Sanity project
- Configures your dataset
- Asks where to output the Studio files
- Sets up configuration files
The key is understanding that this creates a Sanity Studio project - its own set of files and configuration. You can specify where these files should go using the --output-path option:
npx sanity@latest init --output-path studioThis would create a studio folder within your Next.js project containing all the Sanity Studio files.
Integration Options
After initialization, you have two main approaches:
- Embedded Studio: You can embed the Studio as a route in your Next.js app (like
/studio), making it accessible alongside your main application - Separate Studio: Run the Studio separately (different port or deployed independently) and just use the Sanity client in your Next.js app to fetch content
Quick Setup
For unattended setup with defaults:
npx sanity@latest init -y --project <your-project-id> --dataset production --output-path studioAfter initialization, you'll need to install the necessary packages (like next-sanity) to connect your Next.js app to fetch content from Sanity. The init command sets up the Studio; connecting your Next.js frontend to query that content is a separate step using Sanity's client libraries.
Sanity – Build the way you think, not the way your CMS thinks
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.