CLI
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.
--help for an overview of its arguments (for example nitro build --help), and nitro --version prints the installed Nitro version.All commands 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.
vite dev, vite build, vite preview) — the Nitro dev server does not support the Vite builder.nitro dev
Start the development server with hot reloading.
npx nitro dev [--dir <dir>] [--port <port>] [--host <host>]
| Flag | Description |
|---|---|
--dir | Project root directory. |
--port | Port to listen on. |
--host | Hostname to listen on. |
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.
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>]
| 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, or vite (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). |
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 prepare
Generate the project types (in node_modules/.nitro/types by default) without building.
npx nitro prepare [--dir <dir>]
| Flag | Description |
|---|---|
--dir | Project root directory. |
nitro prepare in a postinstall script keeps generated types up to date for your editor after each install.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 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. |
All nitro build flags (--preset, --minify, --builder, --compatibility-date, ...) are also accepted and applied to the build step. Any arguments after -- are appended to the underlying deploy command.
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).
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
Explore the Nitro documentation from your terminal (powered by mdzilla), optionally starting at a specific page path.
npx nitro docs [page]