はりうすブログ (のすけのメモ)

湘南にある小さな会社 代表 ”のすけ”のブログです

Nuxt.js をPM2でデーモン化しながら起動する方法 最新版

Nuxt.js2系にリプレースして、PM2での起動方法が変わったため

紹介しておきます。


PM2のインストール

$ npm install pm2 -g


次にecosystem.config.jsに以下のように記述

module.exports = {
  apps: [
    {
      name: 'NuxtAppName',
      exec_mode: 'cluster',
      instances: 'max', // Or a number of instances
      script: './node_modules/nuxt/bin/nuxt.js',
      args: 'start'
    }
  ]
}


ここのscriptを呼び出す部分がキモですね
script: './node_modules/nuxt/bin/nuxt.js',


そしてビルド開始

npm run build


ecosystem.config.jsを読みながらデーモン化したサーバー起動

pm2 start


起動している事を確認

pm2 ls


ログを確認

pm2 logs

以上!


参考
How to deploy using PM2 cluster mode? - NuxtJS