Unitech / Unitech/pm2

arguments and options from cli are passed to the forked child process

Open
#5,335 0 comments 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

env: nodejs: v16.14.3 pm2: v5.2.0

I tried to pass the arguments and options to my app script, like the following

pm2 start app.js --no-deamon -- ./entry.js --config ./config/prod.js

If I print process.argv in app.js, the result will be
["start", "app.js", "--no-daemon", "--", "./entry.js", "--config", "./config/prod.js", "./entry.js", "--config", "./config/prod.js"]
(ignore argv[0] and argv[1])

In my situation, the app script is in a npm package, it need a argument and a option to specific its entry and config. It is clear that I get wrong process.argv. My app script launch as
app.js ./entry.js --config ./config/prod.js
Using pm2, it will be
app.js start app.js --no-daemon ...(ignore)

In usually, arguments and options after -- should be ignore in current process and pass to the next process, but pm2 not.

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 reproducing the reported command with Node.js v16.14.3 and PM2 v5.2.0, then trace the CLI argument parsing and child-process launch path. Done means arguments and options after -- are passed once to the app without PM2's own command arguments appearing in process.argv.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
backend, cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.