NodeJS创建 HTTP 服务器

 nodejs不像  .net  java需要一个单独的IIS或者tomcat;它能直接创建一个http服务器

代码如下:

var http = require('http');
http.createServer(function(req, res){
res.writeHead(200, {'Content-type' : 'text/html'});
res.write('<h1>我是学习nodejs的菜鸟</h1>');
res.end('<p>Hello World</p>');
}).listen(3000);

另存为server.js  中文需要另存为utf-8或者GBK编码才支持中文

cmd 启动服务

chrome 访问

 

如果访问为乱码请设置浏览器的编码为utf-8

 

posted on 2015-07-12 22:06  Martin cheng  阅读(213)  评论(0编辑  收藏  举报

导航