日期:2014-05-16 浏览次数:20394 次
软件首页:http://nodejs.org
?
var fs = require('fs'); var file = fs.readFileSync(path, "utf8"); console.log(file); ?
编写的一个简单的 HTTP 服务器
?
var sys = require(sys),
http = require(http);
server = http.createServer(function (req, res) {
? res.writeHeader(200, {Content-Type: text/plain});
? res.write(Hello World);
? res.close();
})
server.listen(8000);
sys.puts(Server running at a href="http://127.0.0.1:8000/);
?
读取mongoDB并输出json数据
var express = require('express');
var app = express.createServer();
var db = require('./tea/db');
db.open({dbName:'comments'});
app.get('/',function(req,res){
db.findOne('comments',{},function(records){
res.send(records);
});
});
app.listen(8001);
var tea = exports;
tea.hello = function(){
console.log('hello world');
}
var mongo = require('mongodb');
var tea = tea || {};
tea.db = exports;
tea.db.server = '127.0.0.1';
tea.db.port = 27017;