Nuxt 3 is powered by a new server engine, code-named "Nitro".
This engine has many benefits:
There are a number of key features, including:
- Handlers can directly return objects/arrays for an automatically-handled JSON response
Handlers can return promises, which will be awaited (
next()are also supported)
- Helper functions for body parsing, cookie handling, redirects, headers and more
Check out the h3 docs for more information.
Nitro allows 'direct' calling of routes via the globally-available
$fetch helper. This will make an API call to the server if run on the browser, but will simply call the relevant function if run on the server, saving an additional API call.
$fetch API is using ohmyfetch , with key features including:
- Automatic parsing of JSON responses (with access to raw response if needed)
Request body and params are automatically handled, with correct
Content-Typeheaders being added
For more information on
$fetch features, check out ohmyfetch .
When using API routes (or middleware), Nitro will generate typings for these routes as long as you are returning a value instead of using
res.end() to send a response.
You can access these types when using
Nitro produces a standalone server dist that is independent of
The server in Nuxt 2 is not standalone, but requires part of nuxt core to be involved running
nuxt start (with the
nuxt distributions) or custom programmatic usage, which was fragile and prone to breakage and not suitable for serverless and service-worker environments.
This dist is generated when running
nuxt build into a
The output is combined with both runtime code to run your Nuxt server in any environment (including experimental browser Service Workers!) and serve you static files, making it a true hybrid framework for the JAMstack. In addition, a native storage layer is implemented, supporting multi source, drivers and local assets.