Different ways to initialize a Sanity project: npm create vs sanity init

3 replies
Last updated: Dec 21, 2022
Hi, Sanity newbie here!
I'm currently working through the Sanity Documentation to get Sanity up and running but I've discovered several ways to do this and I'm finding it confusing. For instance, in the section
Getting Started, the following commands are used:

npm create sanity@latest -- --template clean --create-project "Sanity Project" --dataset production

npm run dev

then in the section
Setting up with Sanity, these commands:

npm install -g @sanity/cli

sanity init

sanity start

and the video tutorial:


npm create sanity@latest


I was wondering if anyone could help me to gain some clarity with this and explain the differences between the approaches?
Please forgive me if this question seems really simple
😳
Thanks!
AI Update

Great question! This can definitely be confusing for newcomers. Let me break down the different approaches you've found:

This is the current, recommended approach for starting new Sanity projects. The npm create sanity@latest command:

  • Doesn't require global CLI installation
  • Walks you through an interactive setup
  • Automatically installs dependencies
  • Sets up your project with modern defaults
  • Uses npm run dev to start the development server

The command you found with all the flags (--template clean --create-project "Sanity Project" --dataset production) is just the non-interactive version of this same approach, where you specify everything upfront instead of answering prompts.

The Legacy Way: npm install -g @sanity/cli + sanity init

This is the older approach that involves:

  1. Installing the Sanity CLI globally
  2. Running sanity init to set up your project
  3. Using sanity start to run the development server

While this still works, it's considered the legacy method. The main differences:

  • sanity start is the old command for running the dev server
  • sanity dev (or npm run dev) is the modern equivalent used with Studio v3+, with better performance and Vite-powered live reloading

What You Should Use

Go with npm create sanity@latest - it's simpler, doesn't pollute your global npm packages, and follows modern JavaScript tooling conventions. After setup, you'll use npm run dev to start your Studio at http://localhost:3333.

The documentation showing different approaches likely reflects different versions or specific use cases. The video tutorial showing just npm create sanity@latest (without flags) is the most beginner-friendly - it'll walk you through everything interactively.

No need to feel embarrassed - Sanity's documentation does show multiple paths, and it's totally reasonable to be confused when you're just starting out! 😊

Show original thread
3 replies
Hey
user G
! Welcome! I can definitely see how this is confusing πŸ™‚
This command installs the CLI tooling and allows you to run Sanity commands from your command line:

npm install --global sanity@latest
The simplest command you can run to create a project is that last one:

npm create sanity@latest
This will then take you through the process of configuring your project by asking you questions in the command line.

If you already know the answer to those questions, though, you can skip them entirely by adding those flags, like in this command:

npm create sanity@latest -- --template clean --create-project "Sanity Project" --dataset production
To break it down:

npm create sanity@latest
- create a Sanity project on the latest version
-- --template clean
- use a blank Studio with no prepopulated schema or data
--create-project "Sanity Project"
- make a new project (instead of selecting an existing on) and name it 'Sanity Project'
--dataset production
- create a dataset named production and add it to the project config.
Note: that middle set of commands you shared is for a V2 Studio and are considered deprecated.
Thanks for the prompt response.
Your comment, '_*Note: that middle set of commands you shared is for a V2 Studio and are considered deprecated.'*_ cleared it all up for me! Maybe it would help others to mention this information about Version 2 here:
https://www.sanity.io/docs/getting-started-with-sanity-cli ?
Thanks again for the concise explanation.
For sure! Thanks for pointing it out!

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?