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
below a simple http server and how to get the listening port
var http = require("http");
function onRequest(request, response) {
console.log("Request received.");
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}
var server =http.createServer(onRequest).listen(process.env.PORT, function(){
console.log('Listening on port '); //Listening on port 8888
});
then get the server port by using :
console.log('Express server started on port %s', server.address().port);