I'm trying to deploy node app on windows server 2012 R2 and facing issue while doing the same.
Server: Windows Server 2012 R2
1) I've installed IIS node from https://github.com/tjanczuk/iisnode/wiki/iisnode-releases [iisnode for iis 7/8(x64)]
2) Installed URL Rewrite module from https://www.iis.net/downloads/microsoft/url-rewrite
3) Placed all node app files at a certain location.
4) From that project directory, issued npm install to install required packages.
server.js
require('rootpath')();
var express = require('express');
var app = express();
var cors = require('cors');
var bodyParser = require('body-parser');
var config = require('config.json');
app.use(cors());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// routes
app.use('/users', require('./services/user.service'));
app.use('/tools', require('./services/tool.service'));
app.use('/orders', require('./services/order.service'));
app.use('/util', require('./services/util.service'));
// start server
var port = 9025;
var server = app.listen(port, function () {
console.log('Server listening on port ' + port);
});
web.config
<configuration>
<system.webServer>
<!-- indicates that the server.js file is a node.js application
to be handled by the iisnode module -->
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />
</handlers>
<!-- use URL rewriting to redirect the entire branch of the URL namespace
to server.js node.js application; for example, the following URLs will
all be handled by server.js:
-->
<rewrite>
<rules>
<rule name="rewriteRule">
<match url="/*" />
<action type="Rewrite" url="server.js" />
</rule>
</rules>
</rewrite>
<!-- exclude node_modules directory and subdirectories from serving
by IIS since these are implementation details of node.js applications -->
<security>
<requestFiltering>
<hiddenSegments>
<add segment="node_modules" />
</hiddenSegments>
</requestFiltering>
</security>
</system.webServer>
</configuration>
Then using IIS, I've created one website who refers to this particular project folder. Provided port number as 9025 while creating website. When I'm trying to access this URL from other machine i.e. http://servername:9025/ I'm getting the below error:
I even tried using process.env.PORT instead of directly using 9025. At that time I'm getting 404 not found.
Please let me know what am I doing wrong?
I found one blog to installing and runing nodejs application within IIS on window install iisnode: https://www.hanselman.com/blog/installing-and-running-nodejs-applications-within-iis-on-windows-are-you-mad