Node.js Using IISNode to host Node.js Web Apps in IIS Using Socket.io with IISNode

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

To get Socket.io working with IISNode, the only changes necessary when not using a Virtual Directory/Nested Application are within the Web.config.

Since Socket.io sends requests starting with /socket.io, IISNode needs to communicate to IIS that these should also be handled IISNode and aren't just static file requests or other traffic. This requires a different <handler> than standard IISNode apps.

<handlers>
    <add name="iisnode-socketio" path="server.js" verb="*" modules="iisnode" />
</handlers>

In addition to the changes to the <handlers> we also need to add an additional URL rewrite rule. The rewrite rule sends all /socket.io traffic to our server file where the Socket.io server is running.

<rule name="SocketIO" patternSyntax="ECMAScript">
    <match url="socket.io.+"/>
    <action type="Rewrite" url="server.js"/>
</rule>

If you are using IIS 8, you'll need to disable your webSockets setting in your Web.config in addition to adding the above handler and rewrite rules. This is unnecessary in IIS 7 since there is no webSocket support.

<webSocket enabled="false" />



Got any Node.js Question?