Introduction
When deploying applications developed with Nuxt 3 and similar frameworks, I often use GitHub Pages, Netlify, AWS Amplify, and Serverless Framework + Lambda. However, this time I had the opportunity to deploy using a VPS, so this is a memo.
References
Specifically, I use Amazon Lightsail and pm2.
Creating an Amazon Lightsail Instance
Select the Node.js blueprint.

Also, since port 3000 is used, open the firewall for it.

pm2 Configuration
I referred to the following article.
https://it-evo.jp/blog/blog-70/
Installation
sudo su
npm install pm2 -g
Downloading and Building Nuxt 3
Download the sample program.
su bitnami
cd /home/bitnami/
git clone https://github.com/nakamura196/nuxt3-pm2
Setup
cd nuxt3-pm2
npm install
Build
npm run build
npm run preview
You can verify the Nuxt 3 application at localhost:3000.
Starting with pm2
cd /home/bitnami/
vi /home/bitnami/ecosystem.config.js
module.exports = {
apps: [{
name: 'demo',
cwd: '/home/bitnami/nuxt3-pm2',
exec_mode: 'cluster',
instances: 'max',
script: './.output/server/index.mjs',
watch: ['./'], // or true
watch_options: {
followSymlinks: true,
usePolling: true,
interval: 10000,
binaryInterval: 10000,
},
env: {
PORT: 3000,
NODE_ENV: 'production',
}
}]
}
Start pm2 with the following command.
pm2 start /home/bitnami/ecosystem.config.js

Daemonization
As a future TODO, as mentioned in the following article, placing pm2 under systemctl management is one consideration.
https://zenn.dev/ukkz/articles/c19541f75754c7#さらにデーモン化する
I would like to try this on another occasion.
Summary
I was able to deploy a Nuxt 3 application using pm2 on a VPS (Amazon Lightsail) environment. We hope this is helpful for deploying Nuxt 3 applications in non-serverless environments.