Node.js初学

一.安装及环境配置:

两篇文章介绍的非常详细了

http://www.cnblogs.com/seanlv/archive/2011/11/22/2258716.html

http://www.tuicool.com/articles/UJNb2eJ

二.测试案例(已解决中文乱码问题)

var http = require("http"); 
http.createServer(function(request, response) { 
response.writeHead(200, { "Content-Type": "text/plain;charset=utf-8" });
response.write("NODE正在运行中,此处测试"); 
response.end(); 
}).listen(8899); 
console.log("Node运行中,正在监听8899端口!");

其中解决乱码问题需要关注两点:

(1)JS文件设置编码

response.writeHead(200, { "Content-Type": "text/plain;charset=utf-8" });

(2)更改JS文件编码格式为utf-8

可由记事本打开JS文件,选择“文件”-“另存为”,查看编码格式是否为utf-8,如不是则修改后存储。

原文地址:https://www.cnblogs.com/yanpo/p/6025117.html