node.jsexpressiisreverse-proxyiisnode

Deploying NodeJS application in IIS server


For the first time I am working on deployment of Angular application with Node JS as backend . I am looking for experts suggestions on certain questions. NodeJS version 20 and Angular 17

  1. To deploy NodeJS application, I see two ways, using IISNode and implementing reverse proxy. But I read that IISNode is not getting support anymore does it mean, I cannot use IISNode at all?

  2. If I can use, then can I deploy latest version of NodeJS using IISNode. Will that be supported ? I Couldn't see any information regarding this.

  3. If I have to use Reverse proxy what does it really mean? The NodeJS application will be locally running in the server and all the requests will be redirected to it ? What would be the pros and cons ?

  4. I have used express Middleware in my application. Does it require any thing extra for the deployment in IIS server ?

I could see more examples of deployment processes but nothing talks about the right approach to be followed. Can someone please help so that I hope this post could be 1 stop place for all who looks for these answers.


Solution

  • Please find the answers to your questions below:

    1)To deploy NodeJS application, I see two ways, using IISNode and implementing reverse proxy. But I read that IISNode is not getting support anymore does it mean, I cannot use IISNode at all?

    --> With the latest version of the node application it is recommended to use the reverse proxy instead of using iisnode as it has some compatibility issue.

    2)If I can use, then can I deploy latest version of NodeJS using IISNode. Will that be supported ? I Couldn't see any information regarding this.

    --> As a shared in previous answer it is recommended to use the reverse proxy instead of the iiisnode with latest application

    3)If I have to use Reverse proxy what does it really mean? The NodeJS application will be locally running in the server and all the requests will be redirected to it ? What would be the pros and cons ? --> A reverse proxy setup means that IIS acts as a front-facing server, handling HTTP/HTTPS requests from clients. and it will help forward request to your locally running node js application. Pros:

    Cons:

    4)I have used express Middleware in my application. Does it require anything extra for the deployment in IIS server ?

    --> You just need to use the pm2 command to serve the node application no extra configuration is needed.

    Here are the steps to serve the node js with angular app from IIS:

    1)I am assuming you have configured the node js with angular

    2)You can build the angular app by using command: ng build --prod

    3)Create site in iis and use the dist folder as root website path

    4)Install pm2 command: npm install -g pm2

    after that start the server:

    pm2 start server.js

    5)Go to the iis angular website and add rule:

    <system.webServer>
            <rewrite>
                <rules>
                    <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                        <match url="(.*)" />
                        <action type="Rewrite" url="http://localhost:241/{R:1}" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    

    The rewrite url will be your node js application url which you will get by running the pm2 command