node.js解决中文乱码问题

// 引入HTTP模块
let http = require("http")

// 用http模块创建服务
/*
 req 获取URL信息 (request)
 res 浏览器返回响应信息 (response)
*/
http.createServer(function(req,res){
    // 发送http头部
    // HTTP状态值:200:OK
    // 设置HTTP头部,状态码是 200.文件类型是html,字符集是utf-8
    res.writeHead(200, {'Content-Type': 'text/html'});  
    res.write('<head><meta charset="utf-8"/></head>'); 
    res.write("你好,nodejs")
    // 结束响应
    res.end()
}).listen(8001)
原文地址:https://www.cnblogs.com/jongsuk0214/p/9946760.html