How to add a Handler Mapping for Node.js using your web.config file

Instead of using the IIS Manager to add a handler mapping for Node.js, you can add this directly to your website's web.config file.

Look for the <system.webserver> element within the configuration section of the web.config file and add the handler line:


The example below configure your application to push all *.js files to Node.js.

<configuration>
  <system.webServer>
    <handlers>
     <add name="iisnode" path="*.js" verb="*" modules="iisnode" />
    </handlers>
  </system.webServer>
</configuration>

Be aware that if you setup a handler of: *.js, ALL .js files will be processed by the node.js engine.  The side effect of that is some of the JavaScript on your pages may not function correctly because they are no longer being sent to the client’s browser for processing. 


This example will only allow the file test.js to run under Node.js.

<configuration>
  <system.webServer>
    <handlers>
        <add name="iisnode" path="test.js" verb="*" modules="iisnode" />
    </handlers>
  </system.webServer>
</configuration>


Another option is to use .njs files instead of .js, which will allow you to globally map all .njs files to Node.js.

<configuration>
  <system.webServer>
    <handlers>
        <add name="iisnode" path="*.njs" verb="*" modules="iisnode" />
    </handlers>
  </system.webServer>
</configuration>








Add Feedback