CLI
Nitro ships with a nitro command to develop, build, preview, and deploy your project.
When nitro is installed as a project dependency, run it through your package manager (npx nitro, pnpm nitro, yarn nitro, bun nitro, ...) or add it to your package.json scripts:
{
"scripts": {
"dev": "nitro dev",
"build": "nitro build",
"preview": "nitro preview"
}
}Then use npm run dev, pnpm dev, etc. as shown in the quick start guide.
Tip
Every command supports --help for an overview of its arguments (for example nitro build --help), and nitro --version prints the installed Nitro version.
All commands except nitro create accept a project root directory, either as a positional argument (nitro build ./my-app) or with the --dir flag (preferred). It defaults to the current directory. nitro fetch only accepts --dir, as its positional argument is the URL.
Note
Using Nitro as a Vite plugin? Prefer the Vite CLI (vite dev, vite build, vite preview); the Nitro dev server does not support the Vite builder.
#nitro create
Create a new Nitro project from a template. Nitro ships the templates itself, so no download is needed, and the nitro dependency of the new project is set to the version that created it.
npx nitro create [dir] [--template <template>] [--packageManager <name>] [--no-install] [--gitInit] [--force]| Flag | Description |
|---|---|
dir | Directory to create the project in (default: nitro-app, required when run by an AI agent without --template). |
--template, -t | Project template, by builder: vite (full-stack app with a frontend), rolldown (API server, bundled for production), rspack (API server, bundled for production with Rspack, experimental) or runtime (API server without a build step, using builder: false, experimental). |
--packageManager, -p | Package manager to install dependencies with (npm, pnpm, yarn, bun, deno, ...). |
--no-install | Skip installing dependencies. |
--gitInit | Initialize a git repository. |
--force | Write into a non-empty directory, overwriting the files the template creates (a directory with only .git counts as empty). |
When run in an interactive terminal, nitro create prompts for anything not set by a flag. Otherwise it creates the vite template in nitro-app/, installs dependencies with the package manager that ran it (or npm), and fails if the directory is not empty.
Unknown options, options without a value and extra arguments are rejected. When run by an AI agent without a directory or template, it prints the available options and exits, so the agent can choose them explicitly. Once done, it prints a summary of what was created (directory, template, package manager, dependencies and git) followed by the next steps, including when installing dependencies fails.
Example:
npx nitro create my-api --template rolldown --packageManager pnpm#nitro dev
Start the development server with hot reloading.
npx nitro dev [--dir <dir>] [--port <port>] [--host <host>] [--envName <name>]| Flag | Description |
|---|---|
--dir | Project root directory. |
--port | Port to listen on. |
--host | Hostname to listen on. |
--envName | The environment name used to apply $env.<name> config overrides and exposed as import.meta.envName (default: development). |
The dev server watches your Nitro config: changes to runtimeConfig or routeRules are hot reloaded, while other config changes trigger a full dev server restart.
An HTML error page (5xx) opened in the browser reloads by itself once the server reloads after a fix, also with the Vite plugin. It waits on the /_nitro/dev/reload route (under baseURL), which is reserved in development.
Example:
npx nitro dev --port 4000 --host 0.0.0.0#nitro build
Build the project for production. Nitro prepares the build directory, copies public assets, prerenders any configured routes, and bundles the server into the output directory (.output/ by default).
npx nitro build [--dir <dir>] [--preset <preset>] [--minify] [--builder <builder>] [--compatibility-date <date>] [--envName <name>]| Flag | Description |
|---|---|
--dir | Project root directory. |
--preset | The deployment preset to build for (you can also use the NITRO_PRESET environment variable). |
--minify | Minify the output, overriding preset defaults. Use --no-minify to disable minification. |
--builder | The bundler to use: rollup, rolldown, rspack, vite or bun (you can also use the NITRO_BUILDER environment variable). |
--compatibility-date | The date to use for preset compatibility (you can also use the NITRO_COMPATIBILITY_DATE environment variable). |
--envName | The environment name used to apply $env.<name> config overrides and exposed as import.meta.envName (default: production). |
Example:
npx nitro build --preset cloudflare_module#NITRO_PRESET vs --preset
Both set the deployment preset, and the --preset flag takes precedence over the NITRO_PRESET environment variable. The environment variable is handy on deployment platforms and in CI, where you often cannot change the build command:
NITRO_PRESET=cloudflare_module npm run build#nitro preview
Start a local server to preview the production build output.
npx nitro preview [--dir <dir>] [--port <port>] [--host <host>]| Flag | Description |
|---|---|
--dir | Project root directory. |
--port | Port to listen on. |
--host | Hostname to listen on. |
Example:
npx nitro build
npx nitro preview#nitro serve
Start the server from the project sources, without a build step (alias: nitro start).
npx nitro serve [--dir <dir>] [--port <port>] [--host <host>] [--dev] [--envName <name>]| Flag | Description |
|---|---|
--dir | Project root directory. |
--port | Port to listen on (defaults to the NITRO_PORT or PORT environment variable, then 3000). |
--host | Hostname to listen on (defaults to the NITRO_HOST or HOST environment variable). |
--dev | Start in development mode, like nitro dev without a builder. |
--envName | The environment name used to apply $env.<name> config overrides and exposed as import.meta.envName (default: production, or development with --dev). |
The server runs in production mode without a builder (builder: false), whatever builder is configured: your files run directly in the server process, and public assets are served from their source directories. With buildPlugins, whose hooks may be async, they run in a Node.js worker that listens on the port itself instead. WebSocket handlers and scheduled tasks are supported. Environment variables are loaded from .env.production and .env files, without overriding existing ones.
On SIGINT or SIGTERM, the server stops accepting connections, waits for in-flight requests and runs the close hooks before exiting. If the server (or its worker) exits unexpectedly, the command exits with code 1 so a process manager can restart it.
Warning
Running without a builder is experimental. Bundler options and plugins added with the build:config hook do not apply, see builder for the details.
Example:
npx nitro start --port 8080#nitro fetch
Send one request to the server from the project sources, without a build step, print the response and exit (alias: nitro curl).
npx nitro fetch [url] [--dir <dir>] [--no-dev] [--envName <name>] [curl options]The URL can be a path (/api/hello, resolved against http://localhost) or a full URL starting with http:// or https://. It defaults to /. Its host is sent as the host header (unless set with -H), so the server sees it. The project root directory is only set with --dir, as the positional argument is the URL.
When nitro dev (or vite dev with the Vite plugin) is running for the project, the request is sent to that dev server, so you get the current code with its dev behavior (public assets, devProxy, ...), and its logs stay in its terminal. Otherwise, a server starts like with nitro serve (in production mode, with .env.production and .env files) and closes after the response, running the close hooks. Use --no-dev to always start a server. With --envName, the dev server is only used if it runs with the same environment name (development, unless set with nitro dev --envName). Vite only accepts the hosts of its server.allowedHosts option (and localhost).
The response body is streamed to stdout as it arrives, while the logs go to stderr, so the output can be piped (nitro fetch /api/users | jq).
A subset of the curl options is supported:
| Flag | Description |
|---|---|
-X, --request | Request method (default: GET, POST with a body, or HEAD with --head). |
-H, --header | Request header (Name: value), can be repeated (also with the same name). Name: removes a default header. |
-d, --data | Request body, sent as application/x-www-form-urlencoded (unless set with -H). @file reads a file (without its newlines) and @- stdin. Repeated values are joined with &. |
--data-raw | Like --data, without the @ handling. |
--data-binary | Like --data, keeping the file contents as is. |
--json | JSON request body (@file and @- are read as is), setting the content-type and accept headers to application/json. |
-i, --include | Include the response status line and headers in the output. |
-I, --head | Send a HEAD request and only print the response status line and headers. |
-o, --output | Write the response to a file instead of stdout. |
-s, --silent | Hide the Nitro logs (not the logs of your app) and the error message. |
-v, --verbose | Print the request and response headers and the Nitro info logs (to stderr). |
Redirects are not followed. With a 4xx or 5xx response status, the body is printed and the command exits with code 22 (like curl --fail-with-body). If the output can not be written, for example when stdout is closed early (nitro fetch | head), it stops and exits with code 23. On SIGINT or SIGTERM, it stops and exits with code 130 or 143. Other errors exit with code 1, and invalid arguments with code 2. The server is always closed before exiting, running the close hooks.
Warning
Running without a builder is experimental. Bundler options and plugins added with the build:config hook do not apply, see builder for the details.
Example:
npx nitro fetch /api/hello
npx nitro curl -i -X POST /api/users --json '{"name":"nitro"}'#nitro deploy
Build the project, then run the deploy command of the selected preset.
npx nitro deploy [--dir <dir>] [--prebuilt] [build flags...] [-- <extra deploy args>]| Flag | Description |
|---|---|
--prebuilt | Skip the build step and deploy the existing build output, with the preset and env name of that build. |
All nitro build flags (--preset, --minify, --builder, --compatibility-date, --envName, ...) are also accepted and applied to the build step. Any arguments after -- are appended to the underlying deploy command (or passed as args to a function deploy command).
Note
Not all presets support nitro deploy. If the selected preset does not define a deploy command (or no build output is found), the command fails with an error. In that case, use a different preset, configure a deploy command in your Nitro config, or deploy manually following the deployment guide of your provider.
Example:
# Build with the cloudflare_module preset, then run wrangler deploy
npx nitro deploy --preset cloudflare_module
# Deploy an existing build without rebuilding
npx nitro deploy --prebuilt#nitro task
Operate on Nitro tasks (experimental).
Important
Tasks support is experimental and requires the experimental.tasks flag. The task subcommands work against the currently running dev server, so run them in a second terminal while nitro dev is running. See the tasks documentation for details.
#nitro task list
List available tasks with their descriptions.
npx nitro task list [--dir <dir>]| Flag | Description |
|---|---|
--dir | Project root directory. |
#nitro task run
Run a task by name, optionally with a JSON payload.
npx nitro task run <name> [--dir <dir>] [--payload <json>]| Flag | Description |
|---|---|
--dir | Project root directory. |
--payload | JSON string parsed and passed to the task as its payload. |
Example:
npx nitro task run db:migrate --payload '{"force": true}'#nitro docs
Open the Nitro documentation (nitro.build) in your browser, optionally at a specific page path (e.g. /docs/routing).
npx nitro docs [page]