Hosting node.js applications in IIS
Hosting node.js applications in IIS
- Setup new site on IIS web server and bind your domain name on node application directory path.
- 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' .
- 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);
});
console.log('Listening on port ' + listener.address().port);
});
- Then open node application folder path in cmd. ( Required administrator privileges).
Command: npm install -g node-windows
- 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();
- Then run below command to install service.
Comments
Post a Comment