Using HTTP platform handler to host a node.js application via IIS
Tags: node, hosting, windows, iis
Published: 2020-03-13 22:11:48

---
title: "Using HTTP platform handler to host a node.js application via IIS"
published: true
description: 
tags: ["nodejs", "hosting", "windows", "iis"]
canonical_url: https://eysermans.com/post/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](https://eysermans.com/post/hosting-a-nodejs-application-on-windows-with-iis-as-reverse-proxy). 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](https://dev.to/davidwhit/comment/ho9e). 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](https://eysermans.com/post/hosting-a-nodejs-application-on-windows-with-iis-as-reverse-proxy). 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](https://eysermans.com/images/articles/using-http-platform-handler-to-host-a-node-js-application-via-iis/diagram.png)

I am assuming you already have a node application running, if not please check the [previous post to create a simple hello world example](https://eysermans.com/post/hosting-a-nodejs-application-on-windows-with-iis-as-reverse-proxy).

To install the module, [download the installer](https://www.iis.net/downloads/microsoft/httpplatformhandler) 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>

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:

- [Scott Hanselman wrote about the extension](https://www.hanselman.com/blog/AnnouncingRunningRubyOnRailsOnIIS8OrAnythingElseReallyWithTheNewHttpPlatformHandler.aspx) and [has a video on it](https://azure.microsoft.com/en-in/resources/videos/the-http-platform-handler-with-scott-hanselman/)
- <a href="https://docs.microsoft.com/en-us/previous-versions/azure/windows-server-azure-pack/mt125371(v%3Dtechnet.10)">Microsoft documentation on using the module</a>

This is a cross post from my [own blog](https://eysermans.com/post/using-http-platform-handler-to-host-a-node-js-application-via-iis).