Adding Sanity to existing NextJS project vs new setup

3 replies
Last updated: Dec 1, 2025
Hello, apologies if this has been asked already.I am building a web app using NextJS and I want to utilize Sanity. It says the command
npm create sanity@latest
Is that correct? It sounds like a command for an initial setup for a project, not for a project that already exists. But that just may be how I'm reading this.
AI Update

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 init

The 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 studio

This 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:

  1. Embedded Studio: You can embed the Studio as a route in your Next.js app (like /studio), making it accessible alongside your main application
  2. 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 studio

After 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.

Show original thread
3 replies

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.

Was this answer helpful?