[从入门到脱鞋] Hello Node.js

Hooopo 2010-08-05
hello word:
console.log('hello worold');


Simple HTTP Server:
var http = require('http');

var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end("Hello World\n");
});

server.listen(8000);

console.log("Server running at http://127.0.0.1:8000/");


watch file:
fs = require('fs');
fs.watchFile(__filename, function() {
    console.log('You changed me!');
    process.exit();
});
console.log('need not wait for anybody!');
//启动程序控制台输出need not wait for anybody!
//更改文件后控制台打印You changed me!
//然后退出


passenger重启就是用的这种方式,,只要touch /tmp/restart.txt...

timer:
setTimeout(function () {
    console.log('2s passed');
}, 2000)
console.log("start!");
//输出:
//start!
//2s passed


web sites:http://nodejs.org/
Howtonode:http://howtonode.org
各种资源:http://wiki.github.com/ry/node/
night_stalker 2010-08-06
node.js 怎么连数据库呢,譬如 mongo

edit: http://howtonode.org/express-mongodb

果然很爽
Saito 2010-08-06
引用
fins: mongodb的 node.js驱动有三个,名字分别是:"node-mongodb" "node-mongodb-native" "mongodb-native" ! 我叉! 这让我怎么选啊!


好吧. 我是来黑这玩意的.. .

这玩意前面js 后面 c.. 给我的感觉,用js的唯一原因是js写出callback比较自然.

极其依赖V8. 思想上模仿nginx ..但是内存上大约是nginx的15倍占用率.. 号称比nginx的并发量高几个..(嗯.. 大约1%~2%的样子..) ..

况且现在的版本才0.1 ..  嗯. event loops威武. .
night_stalker 2010-08-06
一个 V8 一个 spider monkey 不觉得很废吗,直接在 mongo 里做就更好了 ...
Hooopo 2010-08-06
引用
Node is similar in design to and influenced by systems like Ruby's Event Machine or Python's Twisted.

和nginx没有可比性阿。。
比内存就更不应该,node可以用js语法写业务逻辑,谁单独用nginx写?
该比的是mongrel thin tornado等
Hooopo 2010-08-06
node的最大优势是no-block io,还有就是js的语法。
虽然no-block io,但是在并行计算方面还不行。。
据说会加入worker模式,拭目以待
Hooopo 2010-09-08
http://shiningray.cn/node-js-coroutine.html
RednaxelaFX 2010-09-08
http://codebetter.com/blogs/matthew.podwysocki/archive/2010/09/07/getting-started-with-node-js-on-windows.aspx
<< 放个链接
Hooopo 2010-09-08
呼呼~fx大神
Hooopo 2010-09-28
各种webworker:

http://developer.yahoo.net/blog/archives/2010/07/multicore_http_server_with_nodejs.html

http://github.com/kriszyp/multi-node

http://github.com/pgriess/node-webworker

Global site tag (gtag.js) - Google Analytics