helloworld
The title says it all. Key points are:
- An IIS handler for node.js must be registered in web.config to designate the hello.js
file as a node.js application. This allows other *.js files in this web application
to be served by IIS as static client side JavaScript files.
- The node.js listen address must be specified as 'process.env.PORT' when starting
the listener. When an application is hosted in IIS, the web server controls the
base address of the application, which is provided to the node process via an environment
variable.
- node.js applications can exist side by side with other content types: HTML files,
client side JavaScript files, ASP.NET, PHP, WCF, ...
visit the node.js endpoint at hello.js
debug node.js endpoint at hello.js/debug (requires WebKit enabled browser)
get a client side JavaScript file from helloClient.js
code
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('Hello, world! [helloworld sample; iisnode version is '
+ process.env.IISNODE_VERSION + ', node version is ' + process.version + ']');
}).listen(process.env.PORT);
web.config
<configuration>
<system.webServer>
<!-- indicates that the hello.js file is a node.js application
to be handled by the iisnode module -->
<handlers>
<add name="iisnode" path="hello.js" verb="*" modules="iisnode" />
</handlers>
</system.webServer>
</configuration>