title: How do I reference the process PORT assignment for PM2 in my child script / process?
body: <p>I am experimenting with PM2 for my node.js environment on Ubunty and want to try to figure out how I can take a port number specified in the command line like the following...</p>
  
  <pre><code>$pm2 start test.js --node-args "port=3001 sitename='first pm2 app'"
  </code></pre>
  
  <p>... and then in my target script (test.js in the above example) and use that port number for my .listen port... for example:</p>
  
  <pre><code>    var express = require('express')
      var app = express()
  
      app.get('/', function (req, res) {
        res.send('Hello World!')
      })
  
      app.listen(PORT_NUM_HERE, function () {
        console.log('Example app listening on port ' + PORT_NUM_HERE + '!')
      })
  </code></pre>
  
  <p>I also see that with PM2 I can use a configuration file to define process name, port, etc. and if I do that, same question, how to take the port used in the configuration file and use it in my child script.</p>
  
  <p>example configuration file:</p>
  
  <pre><code>{
    "apps": [
      {
        "name": "futurestudio-homepage",
        "script": "./homepage/server.js",
        "instances": 2,
        "exec_mode": "cluster",
        "env": {
          "NODE_ENV": "production",
          "PORT": "3000",
        }
      }
  }
  </code></pre>
  
  <p>]
  }</p>