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模版。

  • 相关阅读:
    .Netcore 2.0 Ocelot Api网关教程(7)- 限流
    .Netcore 2.0 Ocelot Api网关教程(6)- 配置管理
    .Netcore 2.0 Ocelot Api网关教程(5)- 认证和授权
    .Netcore 2.0 Ocelot Api网关教程(4)- 服务发现
    字符串方法集锦
    location下的属性集锦
    Js apply call方法详解
    所有事件event集锦
    移动端常用默认样式
    原生js的各种方法
  • 原文地址:https://www.cnblogs.com/chenweixuan/p/5645917.html
Copyright © 2011-2022 走看看