title: How to get list nodejs processes/app port and path?
body: <p>As a freelance SysAdmin/Developer  I need to  get/update existing app/web on the client server. Sometime I need to update existing NodeJS app that I don't know the port or the path.</p>
  <p>If I want to know the port, I can do easily by find apache2/PHP app config using <code>apache2ctl -S</code> command. But it's difficult to find the nodeJS app path even I know the port.</p>
  <p>Usually the node app is running using pm2. <code>pm list</code> only show list of processes name/command  like below:</p>
  <pre><code>root@lamp-s-4vcpu-8gb-sgp1-01:~# pm2 list
  ┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
  │ id │ name               │ mode     │ ↺    │ status    │ cpu      │ memory   │
  ├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
  │ 11 │ .com               │ fork     │ 0    │ stopped   │ 0%       │ 0b       │
  │ 6  │ DEV API            │ fork     │ 0    │ stopped   │ 0%       │ 0b       │
  │ 0  │ balance Web        │ fork     │ 7    │ stopped   │ 0%       │ 0b       │
  │ 4  │ balance queue      │ fork     │ 0    │ stopped   │ 0%       │ 0b       │
  │ 9  │ index              │ fork     │ 133… │ online    │ 0.3%     │ 144.0mb  │
  │ 10 │ index              │ fork     │ 21   │ online    │ 0.2%     │ 134.5mb  │
  │ 12 │ index              │ fork     │ 13   │ online    │ 0.4%     │ 155.4mb  │
  │ 7  │ longbgst           │ fork     │ 52   │ online    │ 0%       │ 40.0mb   │
  │ 8  │ npm                │ fork     │ 220… │ stopped   │ 0%       │ 0b       │
  │ 2  │ npm run staging    │ fork     │ 116… │ stopped   │ 0%       │ 0b       │
  │ 1  │ old                │ fork     │ 0    │ stopped   │ 0%       │ 0b       │
  │ 5  │ v-api dev          │ fork     │ 0    │ stopped   │ 0%       │ 0b       │
  │ 3  │ develop API        │ fork     │ 358… │ stopped   │ 0%       │ 0b       │
  └────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
  [PM2][WARN] Current process list running is not in sync with saved list. Type 'pm2 save' to synchronize or enable autosync via 'pm2 set pm2:autodump true'
  </code></pre>
  <p>and <code>pm2 show</code> command only show path not the port example:</p>
  <pre><code>root@lamp-s-4vcpu-8gb-sgp1-01:~# pm2 show 10
   Describing process with id 10 - name index
  ┌───────────────────┬─────────────────────────────────────────┐
  │ status            │ online                                  │
  │ name              │ index                                   │
  │ namespace         │ default                                 │
  │ version           │ 1.0.0                                   │
  │ restarts          │ 21                                      │
  │ uptime            │ 2D                                      │
  │ script path       │ /var/www/api-path-id/dist/index.js      │
  │ script args       │ N/A                                     │
  │ error log path    │ /root/.pm2/logs/index-error.log         │
  │ out log path      │ /root/.pm2/logs/index-out.log           │
  │ pid path          │ /root/.pm2/pids/index-10.pid            │
  │ interpreter       │ node                                    │
  │ interpreter args  │ N/A                                     │
  │ script id         │ 10                                      │
  │ exec cwd          │ /var/www/api-path-id                    │
  │ exec mode         │ fork_mode                               │
  │ node.js version   │ 11.15.0                                 │
  │ node env          │ api_path_id                             │
  │ watch &amp; reload    │ ✘                                       │
  │ unstable restarts │ 0                                       │
  │ created at        │ 2020-11-16T03:29:39.945Z
  </code></pre>
  <p>Usually I need to look up using <code>pm2 show</code> command for each pm2 process to find the app path then got to the path and find the port on .env/config file. It's very take a long time if there are so many processes. Is any faster way to see list of running nodejs app with the port and path?</p>
  <p>I tried commands from <a href="https://stackoverflow.com/questions/53336086/where-can-i-find-the-ports-of-all-running-pm2-apps">this question</a> answer but not returned path or process name like below:</p>
  <pre><code>root@lamp-s-4vcpu-8gb-sgp1-01:~# ss -tnlp | grep &quot;node /&quot;
  LISTEN   0         128               127.0.0.1:6030             0.0.0.0:*        users:((&quot;node /var/www/v&quot;,pid=26000,fd=25))
  LISTEN   0         128                 0.0.0.0:6031             0.0.0.0:*        users:((&quot;node /var/www/a&quot;,pid=26006,fd=25))
  LISTEN   0         128               127.0.0.1:6039             0.0.0.0:*        users:((&quot;node /var/www/a&quot;,pid=26013,fd=25))
  root@lamp-s-4vcpu-8gb-sgp1-01:~#
  root@lamp-s-4vcpu-8gb-sgp1-01:~# ss -ntlp | grep $(pm2 ls | grep &quot;SITENAME&quot; | awk '{print $10}') | awk '{print $4}'
  Usage: grep [OPTION]... PATTERN [FILE]...
  Try 'grep --help' for more information.
  </code></pre>
  <p><code>ss -lntp | grep node</code> command show all port but it gives wrong path (maybe cutted/substr).</p>
  <pre><code>root@lamp-s-4vcpu-8gb-sgp1-01:~# ss -lntp | grep node
  LISTEN   0         128               127.0.0.1:6030             0.0.0.0:*        users:((&quot;node /var/www/v&quot;,pid=26000,fd=25))
  LISTEN   0         128                 0.0.0.0:6031             0.0.0.0:*        users:((&quot;node /var/www/a&quot;,pid=26006,fd=25))
  LISTEN   0         128               127.0.0.1:6039             0.0.0.0:*        users:((&quot;node /var/www/a&quot;,pid=26013,fd=25))
  LISTEN   0         128               127.0.0.1:3001             0.0.0.0:*        users:((&quot;node&quot;,pid=29886,fd=24))
  root@lamp-s-4vcpu-8gb-sgp1-01:~# cd /var/www/a
  -bash: cd: /var/www/a: No such file or directory
  </code></pre>
  <p>I need list of port and path(or atleast pm2 process name).</p>