最近开始在学习 Node。 之前只用过 javascript 制作过一些简单的前端特效。 前不久了解到了 Node————表示对"TA"很有兴趣,于是就打算将自己的学习经历记录下来
//load model http
var http = require('http');
/*
*create the http server and listen 3001 port
*req is a client request
*res is a server reponsive
*/
http.createServer(function (req, res) {
//ressend message into the client
res.write('Hello,You hava started the service!');
//on req send the data emit the event
req.on('data', function (chunk) {
log('Reced Data!');
});
//on req end emit the event
req.on('end', function () {
res.end();
log('Req has closed!');
});
}).listen(3001);
log('Server Start');
log('Please open this-http://127.0.0.1:30001 in the Brower!');
function log(str){
console.log(str);
}