Quick Start Node.JS

Programming, error messages and sample code > Node.js
We are Hosting node.js applications in IIS on Windows via httpPlatformHandler, 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="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" />
        </handlers>
        <httpPlatform processPath="node" arguments="hello.js" startupTimeLimit="20" startupRetryCount="2" stdoutLogEnabled="false" stdoutLogFile="log.txt">
            <environmentVariables>
                <environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
                <environmentVariable name="NODE_ENV" value="production" />
            </environmentVariables>
        </httpPlatform>
    </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.