PM2

How to deploy Nuxt to a Node.js hosting using PM2.

PM2 - 图1 Support for ultra-minimal SSR build

PM2 - 图2 Zero-millisecond cold start

PM2 - 图3 More configuration required

Setup

Make sure another preset isn’t set in nuxt.config.

nuxt.config.js|ts

  1. export default {
  2. nitro: {
  3. // this is the default preset so you can also just omit it entirely
  4. // preset: 'node-server'
  5. }
  6. }

Deployment

After running yarn build, all the required files are located in the .output folder. Static assets are in the public subdirectory and the server with its dependencies is within the server subdirectory.

This .output folder can be deployed to your Node.js host and the server can be run using pm2.

To start the server in production mode, run:

  1. node .output/server/index.mjs

For example, using pm2:

ecosystem.config.js

  1. module.exports = {
  2. apps: [
  3. {
  4. name: 'NuxtAppName',
  5. exec_mode: 'cluster',
  6. instances: 'max',
  7. script: './.output/server/index.mjs'
  8. }
  9. ]
  10. }

More information

See more information on the server preset.