Node.js server

Discover the Node.js server preset with Nitro to deploy on any Node hosting.

Node.js server (default) - 图1 Default preset if none is specified or auto-detected

Node.js server (default) - 图2 Loads only the required chunks to render the request for optimal cold start timing

Node.js server (default) - 图3 Useful for debugging

Node.js server (default) - 图4

Back to presets list.

Usage

You can use the Nuxt config to explicitly set the preset to use:

nuxt.config.js|ts

  1. export default {
  2. nitro: {
  3. preset: 'node-server'
  4. }
  5. }

Or directly use the NITRO_PRESET environment variable when running nuxt build:

  1. NITRO_PRESET=server npx nuxt build

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.

  1. node .output/server/index.mjs

Example

  1. $ node .output/server/index.mjs
  2. Listening on http://localhost:3000

Configuring defaults at runtime

This preset will respect the following runtime environment variables:

  • NUXT_PORT or PORT (defaults to 3000)
  • NUXT_HOST or HOST (defaults to 'localhost')
  • NITRO_SSL_CERT and NITRO_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.

Server timings

You can enable the nitro.timing option to have the logs about the chunk loading and cold start performance.

nuxt.config.js|ts

  1. export default {
  2. nitro: {
  3. preset: 'node-server',
  4. timing: true
  5. }
  6. }
  1. $ node .output/server/index.mjs
  2. > Nitro Start (3ms)
  3. Listening on http://localhost:3000
  4. > Load chunks/nitro/static (0ms)
  5. > Load chunks/app/render (1ms)
  6. > Load chunks/app/client.manifest (0ms)
  7. > Load chunks/index (3ms)
  8. > Load chunks/app/server (2ms)
  9. > Load chunks/app/vue3 (0ms)