aizu's Knowledge Base
    • Go to: aizu.my Homepage
    • Recent
    • Tags
    • Register
    • Login

    PM2 for NextJS - ecosystem file

    Linux
    1
    2
    109
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      aizu
      last edited by aizu

      File: ecosystem.config.js

      module.exports = {
          apps: [
              {
                  name: 'service-name-3000',
                  cwd: '/var/www/test',
                  script: 'node_modules/next/dist/bin/next start --port 3000',
                  args: '',
                  watch: false,
                  instances: '1', // Or a number of instances
                  // ignore_watch: ['database'],
                  autorestart: true,
                  env: {
                      PORT: 3000,
                      ENV_PATH: "./.env.local",
                  }
              }
          ]
      };
      
      module.exports = {
        apps: [
          {
            name: 'NextAppName',
            exec_mode: 'cluster',
            instances: '1', // Or a number of instances
            script: 'node_modules/next/dist/bin/next',
            args: 'start -p 5000',
            env_local: {
              APP_ENV: 'local' // APP_ENV=local
            },
            env_development: {
              APP_ENV: 'dev' // APP_ENV=dev
            },
            env_production: {
              APP_ENV: 'prod' // APP_ENV=prod
            }
          }
        ]
      }
      

      Ref: https://dykraf.com/blog/deploying-nextjs-web-application-with-pm2

      1 Reply Last reply Reply Quote 0
      • A
        aizu
        last edited by

        pm2 start npm --name "your-app-name-3000" -- run start

        1 Reply Last reply Reply Quote 0
        • First post
          Last post