Question

I have a simple server that runs fine (below), the problem is that the value of process.env.PORT is not a number as I expected, rather it is a string value like "\\.\pipe\d226d7b0-64a0-4d04-96d4-a75e1278b7a9". How do I get the actual numeric value of the port the http listener is using?

var path = require("path");
var server = require("../server/server.js");
server.start(process.env.PORT, function() {
    console.log("Server started.");
});
Was it helpful?

Solution

Unfortunately you cannot get the port number since IISNode does not use ports and instead uses piped streams which is that random string you see for the port number. If you want to grab the actual HTTP port that the IIS website is running on, you would need to either parse the configuration file that stores this information or set it as an environment variable accessible by Node itself.

Is there a reason you need the port for your application? You shouldn't need the port to run the application as Node will treat that random string as a pipe instead of running server on a port.

OTHER TIPS

answare is not correct. You can dynamically set port number in your app using IIS server variables. https://msdn.microsoft.com/en-us/library/ms524602%28v=vs.90%29.aspx

Just add to webconfig in a tag: iisnode promoteServerVars="SERVER_PORT" then in your express route define:

var portnumber =(req.headers['x-iisnode-server_port'] ||3000)

res.locals.serverport=portnumber

this way it will be using whatever portnumber iis app has, or running standalone mode it will use port 3000.

Cheers Geza

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top