Deploy Nuxt using PM2
How to deploy Nuxt with PM2 cluster mode enabled?
Deploying using PM2 (Process Manager 2) is a fast and easy solution for hosting your universal Nuxt application on your server or VM.
In this guide, we build the application locally and serve it through a PM2 config file with the cluster mode activated. Cluster mode will prevent downtime by allowing applications to be scaled across multiple CPUs.
Getting Started
Make sure you have pm2 installed on your server. If not, simply globally install it from yarn or npm.
# yarn pm2 install
$ sudo yarn global add pm2 --prefix /usr/local
# npm pm2 install
$ npm install pm2 -g
Configure your application
All you need to add to your universal Nuxt app for serving it though PM2 is a file called ecosystem.config.js. Create a new file with that name in your root project directory and add the following content:
module.exports = {
apps: [
{
name: 'NuxtAppName',
exec_mode: 'cluster',
instances: 'max', // Or a number of instances
script: './node_modules/nuxt/bin/nuxt.js',
args: 'start'
}
]
}
Build and serve the app
Now build your app with npm run build.
And serve it with pm2 start.
Check the status pm2 ls.
Your Nuxt application is now serving!
Further Information
This solution guarantees no downtime for your application on this server. (You should also prevent server failure through redundancy or high availability cloud solutions.)
You can find PM2 additional configurations here .
Sébastien Chopin
Nazaré da Piedade
Nobu
川音리오
Maciek Palmowski
Nestor Vera
Daniel Roe
Yue Yang
Jeronimas
Clément Ollivier
Alexander Lichter
N3-rd
Adrien Zaganelli
Mag
Stefan Huber
Olga Bulat
Paiva
Florian Reuschel
Savas Vedova
HIJACK
Vinícius Alves
Kareem Dabbeet
Valentín Costa
Ryan Skinner
Alex Hirzel
Ajeet Chaulagain
René Eschke
Nico Devs
Muhammad
Naoki Hamada
Tom
Yann Aufray
Anthony Chu
Nuzhat Minhaz
Lucas Portet
Richard Schloss
Bobby
bpy
Antony Konstantinidis
Hibariya
Jose Seabra
Eze
Florian Lefebvre
Lucas Recoaro
Julien SEIXAS