Hosting node.js applications in IIS

Hosting node.js applications in IIS

  1. Setup new site on IIS web server and bind your domain name on node application directory path.
  2. Setup Url Rewrite rule of Reverse proxy for your node application port. (Like 3000 or any) 
From above screen shot, you can add Reverse proxy rule directly from IIS Manager or You can put below configuration in web.config.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
<action type="Rewrite" url="{C:1}://localhost:3000/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Followings are the steps to setup node.js application port binding and run as a windows service using 'node-windows' . 


  1. First, you have to add below code in your (application) app.js for static port binding.

var listener = app.listen(3000, function(){
console.log('Listening on port ' + listener.address().port);

});
  1. Then open node application folder path in cmd. ( Required administrator privileges).
Command: npm install -g node-windows

    1. after node-windows installation, Setup your node application to run as a windows service.
For that create one service.js and add below code and save.

var Service = require('node-windows').Service;
// Create a new service object
var svc = new Service({
name:'Hello World',
description: 'The nodejs.org example web server.',
script: 'C:\\path\\to\\helloworld.js'
});
// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install',function(){
svc.start();
});
svc.install();

  1. Then run below command to install service.
The code above creates a new Service object, providing a pretty name and description.
The script attribute identifies the Node.js script that should run as a service.
Upon running this, the script will be visible from the Windows Services utility.

Comments

Popular posts from this blog

Backup & Restore Database as SQL Dump by SqlYog

Postfix can support per-domain outgoing IP addresses, but is not currently configured to do so

Wanna-cry-ransomware