1

When I run my JS file, I use the Writefile() command to create a Json file in the file explorer. This file saves with ANSI encoding. I am wondering if there is a way to run the writefile() command to save the file with 'Unicode' encoding.

Any help is greatly appreciated

Here is the request code I am working with:

const req = https.request(options, function(res) {

    var chunks = [];

    res.on("data", function (chunk) {
        chunks.push(chunk);
    });

    res.on("end", function() {
        var body = Buffer.concat(chunks);
        console.log(body.toString());
    
    const fs = require('fs');
    //const data = JSON.stringify(res);
    fs.writeFile('C:\\Users\\Administrator\\messagesLast2.json', body.toString(), (err) => {
        if (err) {
        throw err;
    }
    console.log("JSON data is saved.");
        }); 
    });
});

0 Answers0