term
cd Web/
touch server.js
server.js
var stream = require('stream'); | |
// Initiate the source | |
var bufferStream = new stream.PassThrough(); | |
// Write your buffer | |
bufferStream.end(new Buffer('Test data.')); | |
// Pipe it to something else (i.e. stdout) | |
bufferStream.pipe(process.stdout); |
var server, ip = "127.0.0.1", | |
port = 1337, | |
http = require('http'), | |
url = require('url'); | |
server = http.createServer(function (req, res) { | |
console.log(req.url); | |
res.writeHead(200, { | |
'Content-Type': 'text/plain' | |
}); | |
res.end('hello world\n'); |
<!DOCTYPE html> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-TW" lang="zh-TW"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<title>node.js index html file</title> | |
</head> | |
<body> | |
<h1>node.js index html file</h1> | |
</body> | |
</html> |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="author" content=""> | |
<meta name="created" content="2012-02-23"> | |
<meta name="modified" content="Thu Feb 23 02:44:31 2012"> | |
<title> Form serialize - Prototype by Caesar Chi</title> | |
<script type="text/javascript" src="http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js"></script> | |
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script> |
/** | |
* @overview | |
* | |
* @author Caesar Chi | |
* @blog clonn.blogspot.com | |
* @version 2012/02/26 | |
*/ | |
// create server. | |
var app = require('express').createServer(), |
function format(format) { | |
if (!FB.String.format._formatRE) { | |
FB.String.format._formatRE = /(\{[^\}^\{]+\})/g; | |
} | |
var values = arguments; | |
return format.replace( | |
FB.String.format._formatRE, | |
function(str, m) { |
var fs = require('fs'); | |
var fullpath = '/home/clonn/test.html'; | |
fs.watchFile(fullpath, function (curr, prev) { | |
if (curr.mtime.getTime() !== prev.mtime.getTime()) | |
console.log('file update'); | |
}); |
var mongo = require('mongodb'); | |
var mongostr = 'mongodb://[user]:[pwd]@alex.mongohq.com:10046/[dbname]'; | |
mongo.connect(mongostr, {}, function(error, db) { | |
if ( ! error) | |
console.log("connected, db: " + db); | |
}); |
var connect = require('connect'); | |
var uid = connect.utils.uid(20); | |
console.log('origin uid: ' + uid); | |
var crypto = require('crypto'); | |
var sha1 = crypto.createHash('sha1'); | |
var d = sha1.update(uid).digest('hex'); | |
console.log('encrypt uid(sha1): ' + d); |