We are Hosting node.js applications in IIS on Windows via IISNode, so you need to update listening port to use "process.env.PORT" in your code.
HelloWorld Sample:
hello.js
var http = require('http');
http.createServer(function(req, res) {
res.writeHead(200, {
'Content-Type': 'text/plain'
});
res.end('Hello, world!');
}).listen(process.env.PORT);
web.config
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="hello.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="mysite">
<match url="/*" />
<action type="Rewrite" url="hello.js" />
</rule>
</rules>
</rewrite>
<!-- Please uncomment the following line to monitor file changes in your application. -->
<!-- <iisnode watchedFiles="*.js;node_modules\*;routes\*.js;views\*;middleware\*.js;controllers\*.js;models\*.js" /> -->
</system.webServer>
</configuration>
You do not have to run any command line with npm or node.exe to host nodejs with us.
Note: Node Modules have to be uploaded to node_modules. You can install node modules locally via npm commands.
Article ID: 1970, Created: April 6, 2018 at 2:04 AM, Modified: May 30 at 5:07 AM