无法使Node JS与中文一起使用

时间:2019-01-14 11:50:50

标签: node.js

我只是使用请求承诺抓取了中文html,将其编码为无,返回缓冲区并使用fs模块保存。

const data = await requestPromise({
            proxy,
            strictSSL: false,
            uri: url,
            encoding: null,
            timeout: 20 * 1000,
        });

fs.writeFileSync('china.html',data)

当我打开china.html时,它会正确打开,显示在此链接上找到的html代码:

https://jsbin.com/texohosopa/1/edit?html

但是当我使用fs.readFileSync(china.txt)从nodejs读取同一文件时,它会返回如下垃圾:

在此链接https://jsbin.com/xuparujeho/1/edit?html中(由于粘贴中文时出错,因此无法在stackoverflow上发布)

应该是节点问题,因为该html页面在chrome上运行良好,但在nodejs上运行不正常。

0 个答案:

没有答案