首页 > Web开发 > 详细

NodeJS学习第一季-HelloWorld

时间:2015-07-12 14:22:30      阅读:339      评论:0      收藏:0      [点我收藏+]

在node-demo 的目录中创建一个index.js

//导入需要的包
var http = require("http");
//创建HTTP服务
http.createServer(function (request, response) {

	// Send the HTTP header 
	// HTTP Status: 200 : OK
	// Content Type: text/plain
	response.writeHead(200, {‘Content-Type‘: ‘text/plain‘});

	// Send the response body as "Hello World"
	response.end(‘Hello World\n‘);
}).listen(8081);

// Console will print the message
// 访问地址
console.log(‘Server running at http://127.0.0.1:8081/‘);

在 命令行工具中 输入 node index.js 回车

系统会打印 

Server running at http://127.0.0.1:8081/

这是在浏览器访问 此地址。页面中会显示 Hello World 程序运行成功!

NodeJS学习第一季-HelloWorld

原文:http://my.oschina.net/xiax/blog/477533

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!