`
zhouyrt
  • 浏览: 1126412 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

nodejs入门

    博客分类:
  • Node
 
阅读更多

首先,去http://nodejs.org 下载安装。我下的版本是0.6.6。安装很简单,下一步下一步就哦了。

我的安装目录是C:\Program Files (x86)\nodejs。

 

 

 

一、helloworld

在nodejs安装目录中新建一个文件hello.js,里面敲一行代码

 

console.log('hello, nodejs.') ;

进入命令行控制台,进入到nodejs目录敲node hello.js

 

控制台输出了“hello, nodejs.”

 

 

二、web版的helloworld

在nodejs安装目录中新建一个http.js,代码如下

var http = require("http");
http.createServer(function(request, response) {
    response.writeHead(200, {"Content-Type": "text/html"});
    response.write("Hello World!");
    response.end();
}).listen(8000);
 

在命令行中启动服务,敲 node  http.js

 

然后打开浏览器地址栏输入http://localhost:8000/,看见页面上输出Hello World! 就成功了。

  • 大小: 1.3 KB
  • 大小: 1 KB
分享到:
评论
1 楼 yangbinfx 2014-01-08  
嗯 大概明白了node.js入门了 看来里面做了很多封装   require("http");    require("util");    

相关推荐

Global site tag (gtag.js) - Google Analytics