You often see example hello world code for Node that creates an Http Server, starts listening on a port, then followed by something along the lines of:
conso
In case when you need a port at the time of request handling and app is not available, you can use this:
request.socket.localPort