Co-authored-by: Daniel Roe <daniel@roe.dev> Co-authored-by: Sébastien Chopin <seb@nuxtjs.com> Co-authored-by: Pooya Parsa <pooya@pi0.io> Co-authored-by: pooya parsa <pyapar@gmail.com> Co-authored-by: Clément Ollivier <clement.o2p@gmail.com>
5.2 KiB
navigation.icon | description |
---|---|
uil:rocket | Deploy on a Node.js server, pre-render for static hosting and to serverless or edge environments. |
Deployment
A Nuxt application can be deployed on a Node.js server, pre-rendered for static hosting, or deployed to serverless or edge (CDN) environments.
::alert{type=info} If you are looking for a list of cloud providers that support Nuxt 3, see the list below. ::
Node.js Server
Discover the Node.js server preset with Nitro to deploy on any Node hosting.
::list
- Default output format if none is specified or auto-detected
- Loads only the required chunks to render the request for optimal cold start timing
- Useful for deploying Nuxt apps to any Node.js hosting ::
Entry Point
When running nuxt build
with the Node server preset, the result will be an entry point that launches a ready-to-run Node server.
node .output/server/index.mjs
Example
$ node .output/server/index.mjs
Listening on http://localhost:3000
Configuring Defaults at Runtime
This preset will respect the following runtime environment variables:
NITRO_PORT
orPORT
(defaults to3000
)NITRO_HOST
orHOST
(defaults to'0.0.0.0'
)NITRO_SSL_CERT
andNITRO_SSL_KEY
- if both are present, this will launch the server in HTTPS mode. In the vast majority of cases, this should not be used other than for testing, and the Nitro server should be run behind a reverse proxy like nginx or Cloudflare which terminates SSL.
Using PM2
To use pm2
, use an ecosystem.config.js
:
module.exports = {
apps: [
{
name: 'NuxtAppName',
exec_mode: 'cluster',
instances: 'max',
script: './.output/server/index.mjs'
}
]
}
Using Cluster Mode
You can use NITRO_PRESET=node_cluster
in order to leverage multi-process performance using Node.js cluster module.
By default, the workload gets distributed to the workers with the round robin strategy.
Learn More
:ReadMore{link="https://nitro.unjs.io/deploy/node" title="the Nitro documentation for node-server preset"}
Static Hosting
There are two ways to deploy a Nuxt application to any static hosting services:
- Static site generation (SSG) pre-renders routes of your application at build time.
- Using
ssr: false
to produce a pure client-side output.
Crawl-based Pre-rendering
Use the nuxi generate
command to build your application. For every page, Nuxt uses a crawler to generate a corresponding HTML and payload files. The built files will be generated in the .output/public
directory.
npx nuxi generate
Manual Pre-rendering
You can manually specify routes that Nitro will fetch and pre-render during the build.
defineNuxtConfig({
nitro: {
prerender: {
routes: ['/user/1', '/user/2']
}
}
})
Client-side Only Rendering
If you don't want to pre-render your routes, another way of using static hosting is to set the ssr
property to false
in the nuxt.config
file. The nuxi generate
command will then output an .output/public/index.html
entrypoint and JavaScript bundles like a classic client-side Vue.js application.
defineNuxtConfig({
ssr: false
})
Presets
In addition to Node.js servers and static hosting services, a Nuxt 3 project can be deployed with several well-tested presets and minimal amount of configuration.
You can explicitly set the desired preset in the nuxt.config
file:
export default {
nitro: {
preset: 'node-server'
}
}
... or use the NITRO_PRESET
environment variable when running nuxt build
:
NITRO_PRESET=node-server nuxt build
🔎 Check the Nitro deployment for all possible deployment presets and providers.
Supported Hosting Providers
Nuxt 3 can be deployed to several cloud providers with a minimal amount of configuration:
- :IconCloud{class="h-5 w-4 inline mb-2"} AWS
- :LogoAzure{class="h-5 w-4 inline mb-2"} Azure
- :LogoCloudFlare{class="h-5 w-4 inline mb-2"} CloudFlare
- :IconCloud{class="h-5 w-4 inline mb-2"} Digital Ocean
- :LogoFirebase{class="h-5 w-4 inline mb-2"} Firebase
- :IconCloud{class="h-5 w-4 inline mb-2"} heroku
- :IconCloud{class="h-5 w-4 inline mb-2"} layer0
- :LogoNetlify{class="h-5 w-4 inline mb-2"} Netlify
- :IconCloud{class="h-5 w-4 inline mb-2"} Render
- :IconCloud{class="h-5 w-4 inline mb-2"} Stormkit
- :LogoVercel{class="h-5 w-4 inline mb-2"} Vercel