Listen additional port Microsoft Azure Nodejs

2019-01-08 01:55发布

问题:

I'm running nodejs application (Azure Web App) on port process.env.PORT (1337), default port on Microsoft Azure. Also I need to listen additional port for websocket. On my local I'm using 8000, but seems, that it's closed on Azure.

Are there any additional ports, that I can listen and is it actually possible at all?

回答1:

If you're deploying to an Azure Web App, only ports 80 and 443 are public-facing. This maps to a specific port for your app to listen to, retrievable via process.env.PORT. And if you're running both in Azure and locally, you can easily manage which port you listen to, with something like this, based on your reference to port 1337 in your question:

var port = process.env.PORT || 1337;

If you needed to listen in on multiple ports, or ones different from 80/443, you'd need to deploy to a VM or a Cloud Service (web/worker role). Or deploy multiple web apps.