Unitech / Unitech/pm2

Duplicate environment config with pm2

Open
#5,974 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

I've been using Node v20, passing it --env-file .env.dev in order to set environment variables.

Now, for some package scripts I need to add pm2 support. I see that pm2 forces me to place environment variables into ecosystem.config.js.

Now I have 2 copies of environment variables, ones to be used by pure NodeJS scripts, and ones used by PM2 scripts. I would think that PM2 should be smarter than that, and let us reuse what NodeJS supports natively, but I haven't been able to find how.

Is there a way to avoid duplication of environment configuration in this scenario? I really do not want to maintain environment config in 2 places because of PM2.

My package scripts now look like this:

    "start": "tsc && node --env-file .env.dev ./src/index.js channel=primary",
    "start-dev": "pm2 start ecosystem.config.js --env dev",
    "start-prod": "pm2 start ecosystem.config.js --env prod",

And so now I have to maintain the same environment variables inside .env.dev file, plus inside ecosystem.config.js file, which isn't good maintenance-wise.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the package scripts, .env.dev, and ecosystem.config.js, then inspect PM2's environment-loading and process-start entry points alongside Node's --env-file behavior. Done means the documented PM2 workflow can reuse one environment configuration without maintaining duplicate variables, with the relevant behavior covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
devops, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.