DEV Community

Peter Eysermans
Peter Eysermans

Posted on • Originally published at eysermans.com

Using HTTP platform handler to host a node.js application via IIS

About a year ago I wrote about hosting a Node.js application via IIS. It uses IIS as a reversed proxy to route traffic from IIS to the node.js webserver. To manage the node.js process pm2 was used. Unfortunately I had some problems restarting the pm2 process when the server restarted. This meant downtime everytime the server was restarted until I manually resurrected pm2.

The original post got a lot of comments and in one of them DavidWhit mentioned that the HTTP Platform handler can be used to manage the node.js process. This IIS module will manage a given process and proxy requests to the process it manages. It acts as a reverse proxy and it manages the process, it's even better than the previous solution. It's not limited to node.js processes, it can manage any process. This also makes it a good solution to host Ruby or other platforms on Windows.

HTTP platform handler schema

I am assuming you already have a node application running, if not please check the previous post to create a simple hello world example.

To install the module, download the installer and run it on your server. This module can only be configured using a web.config, there is no GUI element in the IIS Manager to configure it. Add a web.config in the root of the website if there isn't one yet and copy over this configuration.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="httppPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
    <httpPlatform stdoutLogEnabled="true" stdoutLogFile=".\node.log" startupTimeLimit="20" processPath="C:\Program Files\nodejs\node.exe" arguments=".\app.js">
            <environmentVariables>
                <environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
                <environmentVariable name="NODE_ENV" value="Production" />
            </environmentVariables>
        </httpPlatform>
  </system.webServer>
</configuration>
Enter fullscreen mode Exit fullscreen mode

You should check if the paths in the configuration file are correct. Once the file has been saved, that's it. If you visit the the URL configured in the bindings in IIS it will now route the traffic to the node.js webserver which will be managed by IIS.

More info:

This is a cross post from my own blog.

Top comments (6)

Collapse
 
neilmcneely profile image
Neil McNeely

Hi Peter. I was running a web front end virtual machine in Azure , running IIS. The "download the installer" link does not work. Is there an update? Looking for how to get started installing the httpPlatformHandler , maybe something changed? Thank you in advance.

Collapse
 
petereysermans profile image
Peter Eysermans

Hi Neil, I tried the link again and I get redirected to the correct page with the extension: iis.net/downloads/microsoft/httppl...

Is this not working for you?

Collapse
 
neilmcneely profile image
Neil McNeely

So when you click on the green "Install this extension" button, it takes me just to the gallery - webgallery.microsoft.com/gallery

Further reading looks like they are moving this to Core Net ? Seems like taking something that seemed to be very straightforward into something more complicated to implement. Would love to just be able to find the package to install. Let me know what you find. Or if clicking the green button takes you somewhere different. Thanks!

Thread Thread
 
petereysermans profile image
Peter Eysermans

You can download the installer at the bottom of the page. That is how I installed it. I'm not sure if this extension is still being maintained but it does the job. You are right, I also read that they have moved to another module for .net core: github.com/aspnet/IISIntegration/i...

Thread Thread
 
neilmcneely profile image
Neil McNeely

Oh wow! Thank you. I did not see that, tiny font vs BIG GREEN. Thanks again. Going to try it out tomorrow.

Thread Thread
 
petereysermans profile image
Peter Eysermans

They did a good job trying to hide the installer 😀