Quick Start Node.JS

Programming, error messages and sample code > Node.js
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>
    </system.webServer>
</configuration>
You do not have to run any command line with npm or node.exe to host nodejs with us.