zoukankan      html  css  js  c++  java
  • node和iisnode express手工安装

    一、安装node.js的x86版本:

        这样,node.js会安装在C:Program Files (x86) odejs,这符合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:UsersAdministratorDocumentsIISExpressconfig目录下的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模版。

  • 相关阅读:
    严重: Parse error in application web.xml file at jndi:/localhost/ipws/WEBINF/web.xml java.lang.NoSuchMethodException: org.apache.catalina.deploy.WebXml
    Failed to install .apk on device 'emulator5554': timeout解决方法
    java.lang.NoClassDefFoundError:org.jsoup.Jsoup
    Conversion to Dalvik format failed: Unable to execute dex:解决方法
    apache Digest: generating secret for digest authentication ...
    Description Resource Path Location Type Project has no default.properties file! Edit the project properties to set one.
    android service随机自启动
    MVC3 安装部署
    EF 4.3 CodeBased 数据迁移演练
    SQL Server 2008开启sa账户
  • 原文地址:https://www.cnblogs.com/chenweixuan/p/5645917.html
Copyright © 2011-2022 走看看