Node.js安装入门 第一个程序:Hello World

分类:Javascript| 发布:佚名| 查看: | 发表时间:2014/5/12

首先,去upload/2014/5/201405121107530478.png" alt="" >

 

一、helloworld

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

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

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

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

 

二、web版的helloworld

在Node.js安装目录中新建一个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! 就成功了。

365据说看到好文章不转的人,服务器容易宕机
原创文章如转载,请注明:转载自郑州网建-前端开发 http://camnpr.com/
本文链接:http://camnpr.com/javascript/1067.html