Node.js入门

http://nodejs.cn/api/html

Node.js专门为I/O密集型操做和快速构建可扩展性的实时网络应用而设计的。不适用于CPU密集型操做。node

 

一)Hello World数据库

var http = require('http');

http.createServer(function(req,res) {
    res.writeHead(200,{'Content-Type':'text/plain'});
    res.end('Hello World\n');
}).listen(3000,"127.0.0.1");

console.log('Server running at http://127.0.0.1:3000/');

 

二) Moduleexpress

npm install 【module_name】  //须要全局安装时加上-g标记npm

npm search 【module_name】 //搜索模块api

npm docs 【module_name】 //查看模块文档浏览器

npm bugs  【module_name】 //查看bug服务器

npm eidt【module_name】网络

npm view【module_name】//查看过往版本app

可用于搜索模块:

http://blago.dachev.com/modules

 

三)

输入/输出 I/O:

负载平衡器

数据库服务器

Node.js 客户端:能够是任何对服务器请求响应的东西。好比Web浏览器;搜索引擎机器人;电子邮件客户端以及Web Scraper等

 

四) Jade

Jade是缩进的模版引擎。

Jade要比Html简洁得多;

Jade使用缩进来定义HTML文档的层次结构;

在Jade中无需使用标记,编译模版时会自动加入"<>"字符;

Jade中无需关闭HTML标记,在Jade生成HTML时为咱们关闭标记;

html 
<html></html>
section#wrapper 
<section id="wrapper"> </section>
p.highlight
<p class="highlight"></p>
section#wrapper.class-name
<section id="wrapper" class="class-name"></section>
p.first.second.third.fourth
<p class="first second third fourth"></p>

p
  span

<p> <span></span></p>
hi Very Good!!!
<h1>Very Good!!!</h1>

 

 五)Express

$ express --help
$ express【express_name】
$ cd [express_name] && npm install
$ node app.js

 

app.use(path,callback)中的callback既能够是router对象又能够是函数

app.get(path,callback)中的callback只能是函数

express --help

相关文章
相关标签/搜索