How can I get process.env.PORT from a bash script for cloud9?

first the basic question, below the context:

Note: I am using c9.io, the paid cloud9 service, not my own rollout of cloud9.

I am trying to get the port that would be returned from "process.env.PORT" in nodejs while running on cloud9. This is the way you would run a nodejs application on cloud9 instead of specifying a port number directly.

However, I don't want to modify my fileserver.js code for various reasons. I do however have the option of specifying a port as an argument on the command line that invokes fileserver.js.

So - how do I get the same port that process.env.PORT would return in a nodejs app from within a bash script?

Note, I have already tried $PORT - which returns 8080 (not correct).

Context:

I'm trying to run an amber smalltalk FileServer from within cloud9. Modifying the FileServer.js file is probably not an elegant solution as I will have to do it every time it is changed in the amber smalltalk git repository.

$PORT gives you the variable PORT from current shell environment. It could be different for the process. To get the variables from the started server's environment you must know its pid. Then you can run

cat /proc/pid/environ
//or more readable
xargs --null --max-args=1 echo < /proc/pid/environ

Replace pid with the value of server process's pid. You can then extract the PORT variable from above.