node踩坑记录

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Mr_YanYan/article/details/81207460
  • 2018-07-25 返回的字符串编码乱码
res.writeHead(200,{"Content-Type":"text/plain,charset=utf8"}) //错误写法
res.writeHead(200,{"Content-Type":"text/plain;charset=utf-8"})//正确写法
  • 2018-07-26 本来是想拿客户端的IP地址,却总是拿到::1。
//拿IP的代码

  const ip = request.headers["x-forwarded-for"] ||request.connection.remoteAddress ||request.socket.remoteAddress ||(request.connection.socket ? request.connection.socket.remoteAddress : null);
  // 原因:因为我是本地搭建的环境。所以拿到的IP地址总是::1
  • 2018-08-07 node中EventEmitter内存泄漏,报错代码(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limitTrace
解决连接
https://stackoverflow.com/questions/9768444/possible-eventemitter-memory-leak-detected
  • 2018-08-09 读取txt文件,读取过来的数据乱码的解决办法。
解决办法:将txt文本的格式写成utf8的格式的,读取过来,然后toString()就可以。
具体解决办法:https://blog.csdn.net/Mr_YanYan/article/details/81536742
  • 2018-08-09 读写文件对象数据时,文件内容为object,object?
    “`text
    解决办法:使用JSON.stringify()转换为JSON字符串
    ···

猜你喜欢

转载自blog.csdn.net/Mr_YanYan/article/details/81207460