
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
gatsby-cli
Advanced tools
Gatsby command-line interface for creating new sites and running Gatsby commands
The Gatsby command line interface (CLI) is the main tool you use to initialize, build and develop Gatsby sites.
To use the Gatsby CLI you must either:
npm install -g gatsby-cli, where you execute commands with the syntax gatsby new, ornpx, where you execute commands with the syntax npx gatsby newUseful Gatsby CLI commands are also pre-defined in starters as run scripts.
All the following documentation is available in the tool by running gatsby --help.
Available commands are:
newRuns an interactive shell with a prompt that helps you set up a CMS, styling system and plugins if you wish.
To create a new site with the prompt, execute:
gatsby new
You can also skip the prompt and clone a starter directly from GitHub. For example, to clone a new gatsby-starter-blog, execute:
gatsby new my-new-blog https://github.com/gatsbyjs/gatsby-starter-blog
The first argument (e.g. my-new-blog) is the name of your site, and the second argument is the GitHub URL of the starter you want to clone.
Note: The site name should only consist of letters and numbers. If you specify a
.,./or a<space>in the name,gatsby newwill throw an error.
developCompiles and serves a development build of your site that reflects your source code changes in the browser in real time. Should be run from the root of your project.
gatsby develop
Options include:
| Option | Description |
|---|---|
-H, --host | Set host. Defaults to localhost |
-p, --port | Set port. Defaults to env.PORT or 8000 |
-o, --open | Open the site in your (default) browser for you |
-S, --https | Use HTTPS |
--inspect | Opens a port for debugging |
To set up HTTPS, follow the Local HTTPS guide.
To include a URL you can access from other devices on the same network, execute:
gatsby develop -H 0.0.0.0
You will see this output:
You can now view gatsbyjs.com in the browser.
⠀
Local: http://0.0.0.0:8000/
On Your Network: http://192.168.0.212:8000/ // highlight-line
You can use the "On Your Network" URL to access your site within your network.
buildCompiles your site for production so it can be deployed. Should be run from the root of your project.
gatsby build
Options include:
| Option | Description |
|---|---|
--prefix-paths | Build site with link paths prefixed (set pathPrefix in your config) |
--no-uglify | Build site without uglifying JS bundles (for debugging) |
--profile | Build site with react profiling. See Profiling Site Performance with React Profiler |
--open-tracing-config-file | Tracer configuration file (OpenTracing compatible). See Performance Tracing |
--graphql-tracing | Trace (see above) every graphql resolver, may have performance implications. |
--no-color, --no-colors | Disables colored terminal output |
In addition to these build options, there are some optional build environment variables for more advanced configurations that can adjust how a build runs. For example, setting CI=true as an environment variable will tailor output for dumb terminals.
serveServes the production build of your site for testing prior to deployment. Should be run from the root of your project.
gatsby serve
Options include:
| Option | Description |
|---|---|
-H, --host | Set host. Defaults to localhost |
-p, --port | Set port. Defaults to 9000 |
-o, --open | Open the site in your default browser for you |
--prefix-paths | Serve site with link paths prefixed (if built with pathPrefix in your gatsby-config file). |
infoShow helpful environment information which is required in bug reports. Should be run from the root of your project.
gatsby info
Options include:
| Option | Description |
|---|---|
-C, --clipboard | Copy environment information to your clipboard |
cleanDelete the .cache and public directories. Should be run from the root of your project.
gatsby clean
This is useful as a last resort when your local project seems to have issues or content does not seem to be refreshing. Issues this may fix commonly include:
replOpen a Node.js REPL (interactive shell) with context of your Gatsby environment. Should be run from the root of your project.
gatsby repl
Gatsby will prompt you to type in commands and explore. When it shows this: gatsby >, you can type in one of these commands to see their values in real time:
babelrccomponentsdataPathsgetNodes()nodespagesschemasiteConfigstaticQueriesTo exit the REPL:
Ctrl+C or Ctrl+D twice, or.exit and press EnterWhen combined with the GraphQL explorer, these REPL commands could be very helpful for understanding your Gatsby site's data.
Create React App is a command-line tool to set up a new React project with a single command. It provides a similar experience to gatsby-cli but is focused on React applications rather than static site generation.
Next.js is a React framework that provides a CLI for creating and managing projects. It offers server-side rendering and static site generation, making it a versatile alternative to Gatsby for building modern web applications.
Vue CLI is a command-line tool for scaffolding Vue.js projects. It offers a similar set of features to gatsby-cli but is tailored for Vue.js applications, including project creation, development server, and build commands.
FAQs
Gatsby command-line interface for creating new sites and running Gatsby commands
The npm package gatsby-cli receives a total of 189,403 weekly downloads. As such, gatsby-cli popularity was classified as popular.
We found that gatsby-cli demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 10 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.