1.开始javascript
本文部份内容均转载自文章:php
http://www.hanselman.com/blog/InstallingAndRunningNodejsApplicationsWithinIISOnWindowsAreYouMad.aspxjava
https://github.com/tjanczuk/iisnodenode
做者:SCOTT HANSELMANgit
标题:Installing and Running node.js applications within IIS on Windows - Are you mad?github
发布日期:2011.08.28web
2.为何我要在Windows IIS上运行Node.jsexpress
首先,我主要编写的是Asp.Net应用程序,对windows和iis很熟悉,若是在使用Node.js生产的应用若是能部署在IIS上,那么我想很快就能将Node.js开发的应用发布在生产环境中。windows
虽然在IIS运行Node.js上并非最优选择,可是我主要开发企业级应用,单机并发访问量3K、4K足矣并不如大型互联网企业那样会遇到极大的并发、调优压力。浏览器
最后微软有一帮人正在IIS上玩转Node.js,我表示跟着入坑试一试。
3.如何在IIS上运行Node.js
4.学习iisnode
经过上面安装node示例,查看示例发现iis下新增了一个node目录。
这个node目录运行在DefaultAppPool中(.Net 4.0集成)
打开Express示例的文件夹,包括如下内容
在Hello.js中定义了两个不一样的接口myapp/foo、myapp/bar
var express = require('express'); var app = express.createServer(); app.get('/node/express/myapp/foo', function (req, res) { res.send('Hello from foo! [express sample]'); }); app.get('/node/express/myapp/bar', function (req, res) { res.send('Hello from bar! [express sample]'); }); app.listen(process.env.PORT);
在Web.Config中指定了,Hello.js做为入口函数,同时将myapp/*请求映射给hello.js执行
<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> <!-- use URL rewriting to redirect the entire branch of the URL namespace to hello.js node.js application; for example, the following URLs will all be handled by hello.js: http://localhost/node/express/myapp/foo http://localhost/node/express/myapp/bar --> <rewrite> <rules> <rule name="myapp"> <match url="myapp/*" /> <action type="Rewrite" url="hello.js" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
打开示例页http://localhost/node/express/readme.htm进一步查看调用状况
最后打开Chrome浏览器,输入http://localhost/node/express/hello.js/debug,能够远程调试服务,真乃神器也。。
5.总结
node.js + express便可以快速开发RestAPI和模版站点,又能够在iis中进行部署,远程调试,能够知足项目须要。
如下内容参考:Debugger Don't work https://github.com/tjanczuk/iisnode/issues/396
因为IIS7.X不支持WebSockets因此没法使用最新的远程调试器,可是能够经过配置旧的远程调试器(
<iisnode debuggerExtensionDll="iisnode-inspector.dll" />
)来支持IIS7.X,仅须要修改一下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> <!-- use URL rewriting to redirect the entire branch of the URL namespace to hello.js node.js application; for example, the following URLs will all be handled by hello.js: http://localhost/node/express/myapp/foo http://localhost/node/express/myapp/bar --> <rewrite> <rules> <rule name="myapp"> <match url="myapp/*" /> <action type="Rewrite" url="hello.js" /> </rule> </rules> </rewrite> <iisnode debuggerExtensionDll="iisnode-inspector.dll" /> </system.webServer> </configuration>
旧调试器就是丑点。。