Skip to content

Conversation

@bulgarian-beast
Copy link

Q A
Bug fix? no (UX clarification)
New feature? yes (display selected --env profile)
BC breaks? no
Deprecations? no
Tests pass? yes (manual; CI pending)
Fixed tickets N/A
License MIT
Doc PR N/A

Changes

  • Rename the misleading label node envNODE_ENV in pm2 describe.
  • Add a new row in pm2 describe: PM2 --env, which shows the ecosystem profile selected with --env <name> (e.g., test, production).
  • Persist the selected profile name during env merge as pm2_env_name so the UX layer can display it.

Why

Users often confuse the old “node env” label with PM2’s ecosystem profile. This PR:

  • Makes it explicit that the field is the process NODE_ENV.
  • Surfaces the active PM2 environment profile chosen via --env, which previously wasn’t visible anywhere in describe.

Output:

# pm2 describe demo

┌───────────────────┬────────────────────────────────────────┐
│ status            │ online                                 │
│ name              │ demo                                   │
│ namespace         │ default                                │
│ version           │ N/A                                    │
│ restarts          │ 4                                      │
│ uptime            │ 7s                                     │
│ script path       │ /private/tmp/pm2-test/app.js           │
│ script args       │ N/A                                    │
│ error log path    │ /Users/sofian/.pm2/logs/demo-error.log │
│ out log path      │ /Users/sofian/.pm2/logs/demo-out.log   │
│ pid path          │ /Users/sofian/.pm2/pids/demo-0.pid     │
│ interpreter       │ node                                   │
│ interpreter args  │ N/A                                    │
│ script id         │ 0                                      │
│ exec cwd          │ /private/tmp/pm2-test                  │
│ exec mode         │ fork_mode                              │
│ node.js version   │ 24.4.1                                 │
│ NODE_ENV          │ production                             │
│ PM2 --env         │ test                                   │
│ watch & reload    │ ✘                                      │
│ unstable restarts │ 0                                      │
│ created at        │ 2025-08-11T11:46:08.234Z               │
└───────────────────┴────────────────────────────────────────┘

How

  • lib/Common.js
    When merging environment variables, persist the selected profile name on the process config:

    • Set pm2_env_name = <env_name> (or 'default' when unset).
  • lib/API/UX/pm2-describe.js

    • Rename label to NODE_ENV (guarded: shows N/A if unset).
    • Add new row PM2 --env using pm2_env_name (fallback to 'default').

Behavior / Compatibility

  • Output-only change (no runtime/process behavior impacted).
  • If no --env is provided, PM2 --env shows default.
  • If NODE_ENV isn’t set, it shows N/A instead of undefined.
  • No JSON schema or programmatic API changes.

Before / After (example)

Before

│ node env          │ N/A │

After

│ NODE_ENV   │ production │
│ PM2 --env  │ test       │

Test plan (manual)

# Link locally (for manual E2E verification)
npm install
npm link

# Minimal repro
mkdir -p /tmp/pm2-ecosystem-test && cd /tmp/pm2-ecosystem-test
printf 'setInterval(() => {}, 1000)\n' > app.js
cat > ecosystem.config.js <<'EOF'
module.exports = {
  apps: [{
    name: 'demo',
    script: 'app.js',
    env:      { NODE_ENV: 'development' },
    env_test: { NODE_ENV: 'production'  }
  }]
};
EOF

# Start with a named ecosystem env
pm2 start ecosystem.config.js --env test -f

# Verify describe output
pm2 describe demo


┌───────────────────┬────────────────────────────────────────┐
│ status            │ online                                 │
│ name              │ demo                                   │
│ namespace         │ default                                │
│ version           │ N/A                                    │
│ restarts          │ 4                                      │
│ uptime            │ 7s                                     │
│ script path       │ /private/tmp/pm2-test/app.js           │
│ script args       │ N/A                                    │
│ error log path    │ /Users/sofian/.pm2/logs/demo-error.log │
│ out log path      │ /Users/sofian/.pm2/logs/demo-out.log   │
│ pid path          │ /Users/sofian/.pm2/pids/demo-0.pid     │
│ interpreter       │ node                                   │
│ interpreter args  │ N/A                                    │
│ script id         │ 0                                      │
│ exec cwd          │ /private/tmp/pm2-test                  │
│ exec mode         │ fork_mode                              │
│ node.js version   │ 24.4.1                                 │
│ NODE_ENV          │ production                             │
│ PM2 --env         │ test                                   │
│ watch & reload    │ ✘                                      │
│ unstable restarts │ 0                                      │
│ created at        │ 2025-08-11T11:46:08.234Z               │
└───────────────────┴────────────────────────────────────────┘

Notes for reviewers

  • Small, focused diff (two files).
  • Clear UX win with minimal risk.
  • Happy to adjust copy/labels if you prefer different wording.

Unitech and others added 5 commits May 20, 2025 09:41
The label mimicked a sentence rather than the well-known env var name.
This change clarifies that the value shown is the NODE_ENV variable.
Persist the selected ecosystem env profile name during env merge as pm2_env_name, and display it in pm2-describe as 'PM2 --env'. Also guard NODE_ENV display to avoid undefined values. Output-only UX improvement.
@CLAassistant
Copy link

CLAassistant commented Aug 11, 2025

CLA assistant check
All committers have signed the CLA.

bulgarian-beast and others added 4 commits August 11, 2025 14:21
…e result

- Save the provided `--env <name>` as `pm2_env_name` on the computed config.
- Keep env merge order unchanged (deploy -> base env -> env_<name>).
- Mirror `pm2_env_name` onto the returned object so UX (pm2 describe) can read it.
- Do NOT infer or carry over when `--env` is omitted; describe will fall back to "default".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants