nodejs中文乱码问题

node.js暂时不支持GBK或gb2312,所以编程文件(js)需要修改为utf-8格式。

另外如需要返回html代码,在 writeHead 方法中加入 "charset=utf-8" 编码,如下例所示:

1 var http = require("http");
2 
3 http.createServer(function (req, res) {
4     res.writeHead(200, {
5         "Content-Type": "text/html;charset=utf-8"
6     });
7 
8     res.end("<h1>中文测试</h1>");
9 }).listen(3000);