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 though 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 .
Nazaré da Piedade
Mosaab Emam
Sylvain Marroufin
Iljs Путлер Капут
Daniel Roe
Heitor Ramon Ribeiro
Nero
Sébastien Chopin
Clément Ollivier
Yoon Han
Ikko Ashimine
FamCodings
Ayouli
F. Hinkelmann
felipesuri
Christophe Carvalho Vilas-Boas
Leoš Literák
Trizotti
Marcello Bachechi
Rodolphe
Thomas Underwood
Shek Evgeniy
Lukasz Formela
Hugo Torzuoli
Kareem Dabbeet
tramplay
verebelyicsaba
Adam
Nate Butler
Sandra Rodgers
Arpit Patidar
Matthew Kuehn
Steven DUBOIS
Travis Lindsey
syagawa
Maxime
かる
Al Power
Florent Delerue
quanghm
José Manuel Casani Guerra
Unai Mengual
kazuya kawaguchi
Michael Lynch
Tomachi
pooya parsa
Meir Roth