node和iisnode express手工安装
一、安装node.js的x86版本:
这样,node.js会安装在C:\Program Files (x86)\nodejs,这符合iisnode express7版本的期待。
二、安装iisnode express的x86版本
在以下链接:https://github.com/tjanczuk/iisnode/wiki/iisnode-releases,选择iisnode for iis 7 express (webmatrix) 。注意这明显是x86版本,所以默认情况下,node.js也应安装x86版本。目前尚未提供编译好的express的x64版本,需要手工下载iisnode的源码编译。以开发而论,我们使用x86版本即可。安装了iisnode之后,默认在C:\Users\Administrator\Documents\IISExpress\config目录下的applicationhost.config会修改,不需要我们手工修改。
三、在vs2012中创建网站,运行简单的例子:
我们可以创建一个空白的网站,默认只包括一个web.config文件和一个server.js文件。
我们需要在ide的网站菜单中,选择"使用iis express"
1、Web.Config中,我们指定iisnode模块处理server.js:
<configuration>
<system.webServer>
<handlers>
<!-- indicates that the server.js file is a node.js application to be handled by the iisnode module -->
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<!-- Don't interfere with requests for logs -->
<rule name="LogFile" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^[a-zA-Z0-9_\-]+\.js\.logs\/\d+\.txt$" />
</rule>
<!-- Don't interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server.js\/debug[\/]?" />
</rule>
<!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
<rule name="StaticContent">
<action type="Rewrite" url="public{REQUEST_URI}" />
</rule>
<!-- All other URLs are mapped to the Node.js application entry point -->
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True" />
</conditions>
<action type="Rewrite" url="server.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
2、创建server.js文件,包括:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('Hello, world!');
}).listen(process.env.PORT || 8080);
3、在vs2012中运行:
可看到输出的hellow world
4、若需要显示默认页:
可增加一个index.html文件,在server.js里面载入。
四、为vs2012安装typescript模版:
1、下载地址:
http://www.microsoft.com/en-us/download/details.aspx?id=34790
我们选择0.82版本
2、安装:需要重启
3、重启后我们创建一个typescript项目
4、将上述web.config和server.js加入,可正常的启动。
五、node.js的网站开发:
最简易的方式,显然是静态网页加上node.js后端。但由于我们多数时候,需要在服务端创建动态的网页,那么需要一种模版机制,如此可将数据和网页融合起来。所以我们需要express,我们选择ejs模版。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 单线程的Redis速度为什么快?
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 展开说说关于C#中ORM框架的用法!
· SQL Server 2025 AI相关能力初探
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库