node.js 之 Hello,World in Node !

创建一个js文件,把下面的内容粘贴进去,命名为helloworld.js。

//加载 http 模块
var http = require("http");

//创建 http 服务
http.createServer(function(req,res){
    
    //头内容
    res.writeHead(200,{"cintent-type":"text/plain"});
    
    //输出的信息
    res.end("Hello,World!\n");
    
    }).listen(8124,'127.0.1.1');//绑定端口和IP
    
    console.log("服务运行在8124端口")//成功提示

 保存在你的电脑任何一个位置,然后打开你的node编辑器,通过CD命令进入helloworld.js所在的目录输入node helloworld.js 按回车!大功告成!

一个简单的node服务器运行了!振奋人心!

posted @ 2015-03-31 13:51  匠人  阅读(166)  评论(0编辑  收藏  举报