Nuxt docs, chapter by chapter

API — commands, configuration, advanced

The Nuxt CLI and every command with its notable flags, the top-level keys of nuxt.config, the three hook families, the import.meta flags, and the error-code catalogue.

The last part of the reference is operational knowledge: what the CLI can do, what the configuration surface looks like, which hooks exist and where code runs. It is also the part that changed most in the 4.x line (the CLI package, add-template, test, shell completions, stabilised error codes).

Know — the CLI

  • @nuxt/cli provides the nuxt binary (also nuxi, nuxi-ng, nuxt-cli for compatibility); npx nuxi runs outside a project. Global options: --cwd (before or after the command), --logLevel silent|info|verbose, --help; Node.js 18+ for the CLI. Unknown commands resolve to nuxt-* binaries in the project, and nuxt complete <shell> prints shell completions.
  • nuxt dev: --dotenv, --envName, -e/--extends (add a layer), --clear, --no-fork, -p/--port, -h/--host, --clipboard, -o/--open, --https with --sslCert/--sslKey, --publicURL, --public, --qr (QR code for a phone), --tunnel, --profile.
  • nuxt build (--prerender, --preset, --dotenv, --envName, --extends), nuxt generate (prerender everything; --preset, --envName), nuxt preview (serve the build; -p), nuxt analyze (--name, --no-serve), nuxt typecheck (--checker), nuxt prepare (regenerate .nuxt), nuxt cleanup (remove generated dirs), nuxt info (environment report), nuxt devtools enable|disable, nuxt test (runs @nuxt/test-utils; --dev, --watch).
  • npm create nuxt@latest [dir] (-t/--template, -f/--force, --offline, --no-install, --gitInit, --packageManager), nuxt add <module> (--skipInstall, --skipConfig, --dev), nuxt module add|remove|search, nuxt add-template <template> <name> (replaces the deprecated nuxt add <template>; templates api, app, app-config, component, composable, error, layer, layout, middleware, module, page, plugin, server-middleware, server-plugin, server-route, server-util; --force), nuxt build-module (--build, --stub, --sourcemap, --prepare), nuxt upgrade (--dedupe, -f/--force, --channel stable|nightly|v3|v4|…).

Know — nuxt.config top-level keys

  • alias, analyzeDir, app (baseURL, buildAssetsDir, cdnURL, head, layoutTransition, pageTransition, viewTransition, keepalive, rootId, rootTag, spaLoaderTag, teleportId), appConfig, appId, build (transpile, analyze, templates), buildDir, buildId, builder, compatibilityDate, components, css, debug, dev, devServer, devServerHandlers, devtools, dir, esbuild, experimental, extends, extensions, features, future, hooks, ignore, ignoreOptions, ignorePrefix, imports, logLevel, modules, modulesDir, nitro, optimization, pages, plugins, postcss, rootDir, routeRules, router, runtimeConfig, server, serverDir, serverHandlers, sourcemap, spaLoadingTemplate, srcDir, ssr, telemetry, test, theme, typescript, unhead, vite, vue, watch, watchers, webpack, workspaceDir.
  • compatibilityDate pins framework and Nitro behaviour to a date so upgrades do not change defaults silently; debug accepts an object of granular flags (hooks, hydration, templates, …).

Know — hooks

  • App hooks (runtime, both sides): app:created, app:error, app:error:cleared, app:data:refresh, vue:setup, vue:error, app:rendered (server), app:redirected (server), app:beforeMount, app:mounted, app:suspense:resolve, app:manifest:update, link:prefetch, page:start, page:finish, page:loading:start, page:loading:end, page:transition:finish, page:view-transition:start, dev:ssr-logs.
  • Nuxt hooks (build time, in modules and nuxt.config.hooks): kit:compatibility, ready, close, restart, modules:before, modules:done, app:resolve, app:templates, app:templatesGenerated, build:before, build:done, build:manifest, builder:generateApp, builder:watch, pages:extend, pages:resolved, pages:routerOptions, server:devHandler, imports:sources, imports:extend, imports:context, imports:dirs, components:dirs, components:extend, nitro:config, nitro:init, nitro:build:before, nitro:build:public-assets, prerender:routes, vite:extend, vite:extendConfig, vite:configResolved, vite:serverCreated, vite:compiled, webpack:config, schema:extend, schema:resolved, schema:beforeWrite, schema:written.
  • Nitro app hooks (server runtime, in server/plugins): dev:ssr-logs, render:response, render:html, render:island, close, error, request, beforeResponse, afterResponse.

Know — import.meta and error codes

  • import.meta.client, .server, .browser, .nitro, .dev, .test, .prerender, .env, .envName, .url: tell your code where it runs; the build strips dead branches (if (import.meta.server) …).
  • Error codes: Nuxt 4.5 stabilised its error codes (NUXT_E1001 "composable called outside Nuxt context", NUXT_B5001 and other B codes for build-side problems), each with a page under nuxt.com/docs/4.x/errors/<code> giving the cause and the resolution; the code appears in the message so it can be searched or matched in hooks.

How it works

npx nuxt dev --port 3111 --qr --open             # dev server, QR code for a phone, opens the browser
npx nuxt add-template page products/[id]         # scaffold app/pages/products/[id].vue
npx nuxt module add image                        # install + register @nuxt/image
npx nuxt build --prerender                       # hybrid build with prerendering
npx nuxt analyze --no-serve                      # bundle report written to disk
npx nuxt upgrade --dedupe --channel nightly      # try the nightly line
npx nuxt complete zsh > "${fpath[1]}/_nuxt"      # shell completions
nuxt.config.ts
export default defineNuxtConfig({
  compatibilityDate: '2026-09-01',
  debug: { hooks: true, hydration: true },
  hooks: {
    'pages:extend'(pages) {
      pages.push({ name: 'legacy-pricing', path: '/pricing-old', redirect: '/pricing' })
    },
    'build:done'() {
      console.info('build finished')
    },
  },
  nitro: { compressPublicAssets: true },
})
server/plugins/timing.ts
export default defineNitroPlugin((nitroApp) => {
  nitroApp.hooks.hook('request', (event) => { event.context.start = performance.now() })
  nitroApp.hooks.hook('beforeResponse', (event) => {
    setResponseHeader(event, 'Server-Timing', `app;dur=${(performance.now() - event.context.start).toFixed(1)}`)
  })
})
Gotcha· nuxt add vs nuxt add-template

nuxt add <module> now installs a module; scaffolding a file is nuxt add-template <template> <name>. The old nuxt add page foo still works but is deprecated, and older tutorials use it.

Verify before the interview:

The current flag lists (especially --qr, --tunnel, --no-fork) and the nuxt upgrade --channel values; the CLI moves faster than the framework.

docs ↗

Exercise

Exercise
  • Run nuxt info and explain every line; then nuxt analyze --no-serve and open the generated report.
  • Add a pages:extend hook that removes a page and a render:html Nitro hook that injects a meta tag; verify both in the output.
  • Trigger a Nuxt error with a NUXT_E… code (for example by misusing definePageMeta) and open its docs page.

Be able to say

Be able to say· What are the three families of Nuxt hooks and where do you register each?

"App hooks run at runtime inside the Vue app on both server and client, app:created, page:start, page:finish, vue:error, link:prefetch, and I register them in plugins with nuxtApp.hook or in components with useRuntimeHook. Nuxt hooks run at build time, modules:done, pages:extend, components:extend, nitro:config, prerender:routes, and they belong in modules or the hooks key of nuxt.config. Nitro hooks run on the server at runtime, request, beforeResponse, render:html, error, and live in server/plugins through defineNitroPlugin. Knowing which family a problem belongs to is usually the whole answer."

Your notes

Open in Notes

Nothing yet. Notes filed here show up on this page and the section overview.