Q:

NodeJS: How is the value for process.env.PORT assigned?

When I run my NodeJS app the process.env.PORT is undefined. I am noticing this when I try to log the value:
console.log(process.env.PORT) // undefined 
My question is, how to I change that environment object value? Thanks for an answer!

A:

The process.env.PORT variable returns the value of the PORT environment variable. 
If for example app.js is your apps entry point, then accessing process.env.PORT from within your app would yield a value of 8080 if you were to run this on the terminal:
PORT=8080 node app.js 

Update
To specify the PORT environment variable when running your app on Heroku, login to your Heroku account, select your application from the list, click the "settings" tab and then click "Reveal Config Vars". Enter a PORT key with the required port value, and click the "Add" button.

