I am trying to run a very simple node.js server on an Azure Web Appp to serve a single page application. The server will serve up static pages, and will always server \'inde
Windows Azure Websites uses IISNode to host the Node process inside of IIS. Your Node site is actually given a Named Pipe which receives the incoming requests, not a TCP port like you would use when running locally or hosting yourself. Even if you could open a TCP port, Azure Websites are really only meant for traditional websites and don't have a way to open ports to the outside world.
So, first, you need to change the port in your code, e.g.:
var port = process.env.PORT||3000; //which you can run both on Azure or local
var server = app.listen(process.env.PORT||3000);
And in my test, there are several additional configurations we need to configure to remove errors from application to make it run on Azure Web App.
It seems it will raise the same issue with https://github.com/alexmingoia/koa-router/issues/177 directly run koa apps on Azure, so we need to configure the nodeProcessCommandLine:
create a the a file named iisnode.yml with the content:
nodeProcessCommandLine:"%programfiles%\nodejs\%WEBSITE_NODE_DEFAULT_VERSION%\node.exe" --harmony-generators
the setting WEBSITE_NODE_DEFAULT_VERSION is relative to the value you set in app settings in configure tab of in your site manager portal.
As a node.js application running on Azure Web Apps, needs a server.js or app.js file as the entrance in the root directory with a web.config file to control the iis (it will automatically create if you deploy via git or build the app server via node.js template). E.G.
So you can put your SPA files in the public folder in root directory, e.g. your SPA entrance is index.html, when you visit it will rewrite to "/public/index.html".
Additionally, you can leverage VSO to debug your application on Azure online, refer to Visual Studio 2015 and Microsoft Azure syncing files, Server/Local for more.