20121124.Nodejs建立HTTP程序.md

####一、源代码:

    var http =require( 'http'); //读取http模块
    http.createServer( function(req,res){ //建立一个服务,接受一个回调函数,req表示request,res表示response
        res.writeHead( 200,{ 'Content-Type':'text/html'});
        res.write( 'Hello Nodejs');
        res.end( '<p>Allen</p>'); //此处end()方法不能少,不然响应会被挂起
    }).listen(3000);//监听3000端口
    console.log( 'Http server is listenning 3000 port!' );
 
####二、运行命令
 
####三、运行效果


相关文章
相关标签/搜索