2023-10-11 09:11:41 +00:00
---
2023-10-18 10:59:43 +00:00
title: 'Server'
2023-11-15 21:43:03 +00:00
description: Build full-stack applications with Nuxt's server framework. You can fetch data from your database or another server, create APIs, or even generate static server-side content like a sitemap or a RSS feed - all from a single codebase.
2023-10-18 10:59:43 +00:00
navigation.icon: i-ph-computer-tower-duotone
2023-10-11 09:11:41 +00:00
---
2023-10-18 10:59:43 +00:00
:read-more{to="/docs/guide/directory-structure/server"}
2023-10-11 09:11:41 +00:00
## Powered by Nitro
2023-10-20 17:28:55 +00:00
![Server engine ](/assets/docs/getting-started/server.svg )
Nuxt's server is [Nitro ](https://github.com/unjs/nitro ). It was originally created for Nuxt but is now part of [UnJS ](https://unjs.io ) and open for other frameworks - and can even be used on its own.
2023-10-11 09:11:41 +00:00
Using Nitro gives Nuxt superpowers:
- Full control of the server-side part of your app
- Universal deployment on any provider (many zero-config)
- Hybrid rendering
2023-10-20 17:28:55 +00:00
Nitro is internally using [h3 ](https://github.com/unjs/h3 ), a minimal H(TTP) framework built for high performance and portability.
2024-05-13 14:39:52 +00:00
::tip{icon="i-ph-video-duotone" to="https://www.youtube.com/watch?v=DkvgJa-X31k" target="_blank"}
Watch a video from Alexander Lichter to understand the responsibilities of Nuxt and Nitro in your application.
::
2023-10-20 17:28:55 +00:00
## Server Endpoints & Middleware
2023-10-11 09:11:41 +00:00
2023-10-20 17:28:55 +00:00
You can easily manage the server-only part of your Nuxt app, from API endpoints to middleware.
2023-10-11 09:11:41 +00:00
Both endpoints and middleware can be defined like this:
2024-02-16 20:31:15 +00:00
```ts twoslash [server/api/test.ts]
2023-10-18 10:59:43 +00:00
export default defineEventHandler(async (event) => {
2023-10-11 09:11:41 +00:00
// ... Do whatever you want here
})
```
And you can directly return `text` , `json` , `html` or even a `stream` .
2023-10-20 17:28:55 +00:00
Out-of-the-box, it supports **hot module replacement** and **auto-import** like the other parts of your Nuxt application.
2023-10-11 09:11:41 +00:00
2023-10-18 10:59:43 +00:00
:read-more{to="/docs/guide/directory-structure/server"}
2023-10-11 09:11:41 +00:00
## Universal Deployment
Nitro offers the ability to deploy your Nuxt app anywhere, from a bare metal server to the edge network, with a start time of just a few milliseconds. That's fast!
2023-10-18 10:59:43 +00:00
:read-more{to="/blog/nuxt-on-the-edge"}
2023-10-20 17:28:55 +00:00
There are more than 15 presets to build your Nuxt app for different cloud providers and servers, including:
2023-10-11 09:11:41 +00:00
2023-10-18 11:26:06 +00:00
- [Cloudflare Workers ](https://workers.cloudflare.com )
- [Netlify Functions ](https://www.netlify.com/products/functions )
2024-01-28 20:26:08 +00:00
- [Vercel Edge Network ](https://vercel.com/docs/edge-network/overview )
2023-10-11 09:11:41 +00:00
Or for other runtimes:
2023-10-18 10:59:43 +00:00
::card-group
:card{icon="i-logos-deno" title="Deno" to="https://deno.land" target="_blank"}
:card{icon="i-logos-bun" title="Bun" to="https://bun.sh" target="_blank"}
2023-10-11 09:11:41 +00:00
::
2023-10-18 10:59:43 +00:00
:read-more{to="/docs/getting-started/deployment"}
2023-10-11 09:11:41 +00:00
## Hybrid Rendering
Nitro has a powerful feature called `routeRules` which allows you to define a set of rules to customize how each route of your Nuxt app is rendered (and more).
2024-02-16 20:31:15 +00:00
```ts twoslash [nuxt.config.ts]
2023-10-11 09:11:41 +00:00
export default defineNuxtConfig({
routeRules: {
2023-10-18 10:59:43 +00:00
// Generated at build time for SEO purpose
'/': { prerender: true },
// Cached for 1 hour
'/api/*': { cache: { maxAge: 60 * 60 } },
// Redirection to avoid 404
'/old-page': {
2024-01-19 16:41:18 +00:00
redirect: { to: '/new-page', statusCode: 302 }
2023-10-18 10:59:43 +00:00
}
2023-10-11 09:11:41 +00:00
// ...
}
})
```
2023-10-18 10:59:43 +00:00
::read-more{to="/docs/guide/concepts/rendering#hybrid-rendering"}
Learn about all available route rules are available to customize the rendering mode of your routes.
::
2023-10-11 09:11:41 +00:00
2024-03-17 01:40:57 +00:00
In addition, there are some route rules (for example, `ssr` , `appMiddleware` , and `experimentalNoScripts` ) that are Nuxt specific to change the behavior when rendering your pages to HTML.
2023-10-11 09:11:41 +00:00
2024-03-17 01:40:57 +00:00
Some route rules (`appMiddleware`, `redirect` and `prerender` ) also affect client-side behavior.
2023-10-11 09:11:41 +00:00
Nitro is used to build the app for server side rendering, as well as pre-rendering.
2023-10-18 10:59:43 +00:00
:read-more{to="/docs/guide/concepts/rendering"}