Serving Node Applications on Microsoft IIS
Over the weekend I was bored and tried hosting node applications on IIS on a server. Since currently I have only tried wordpress I had no idea how to go about this which might be why you are here, so lets dive straight into how to get i…

Over the weekend I was bored and tried hosting node applications on IIS on a server. Since currently I have only tried wordpress I had no idea how to go about this which might be why you are here, so lets dive straight into how to get it running. So first of all if you haven't done this before you will probably not have node installed on your server. So first lets install everything that we will need.
Prerequisites
- If you do not have IIS (Internet Information Services) enabled; you will have to enable it. Search
Turn Windows Features On or Offand check the box next toInternet Information Services. Expand theInternet Information Servicesnode to select additional features likeWeb Management ToolsandWorld Wide Web Services. Ensure at least the following are selected:
Web Management Tools: IncludesIIS Management Console.World Wide Web Services: Includes various services for hosting websites and applications.
- Install
nodefrom here. Make sure that you add the path tonode.exein yourenvironment variables. In most cases it would beC:\Program Files\nodejs\. - Install
iisnodefrom here. - Install
URL Rewritefrom here.
Creating and Setting up the Site
- Open
IIS Managerand click on your device in theconnectionspanel on the left to expand it. - Right click
Sitesand click on theAdd Website...option to create a new site, and add the domain name you want it to show up on in thehostnameand check thestart website immediately. - Add
127.0.0.1to your Site from thebindingsin the right pane in your site's page in IIS. - Check if
iisnodeis installed inmodules. - Locate the folder
C:\intepub\wwwroot\and create a folder with the same name as your site. - Add the following files to
C:\inetpup\wwwroot\{site name}:
server.jsweb.config
- Open the terminal and install
ExpressJsusingnpm install express. - Write your server script in
server.jsto create anexpressserver.
var express = require("express");
var app = express();
app.get("/ping", function(req, res) {
res.send("Pong!");
});
app.listen(process.env.PORT, () => {
console.log("listening");
});- Add the following to
web.config
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="nodejs">
<match url="(.*)" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="/node_app.js" />
</rule>
</rules>
</rewrite>
<security>
<requestFiltering>
<hiddenSegments>
<add segment="node_modules" />
<add segment="iisnode" />
</hiddenSegments>
</requestFiltering>
</security>
<httpErrors existingResponse="PassThrough" />
<iisnode nodeProcessCommandLine="C:\Program Files\nodejs\node.exe" />
</system.webServer>
</configuration>- This
web.configfile is written inXMLand is used to configure settings for web applications hosted on Internet Information Services (IIS). It allows you to define how IIS should handle requests, manage security settings, rewrite URLs, handle custom error messages, and integrate with specific modules likeiisnodefor hosting Node.js applications.
Note: If you are having trouble creating or editing files in C:\inetput\wwwroot\{your site} , right click and open properties. Add your user if it does not exist and check the full control box to make the process of editing and creating files easier. In most cases this requires administrative control. And with that we have served node applications on IIS!