Search code examples
node.jsencodingfsansi

NodeJS - Saving TXT file with ANSI encoding


I created in my Linux PC a simple app that generates TXT files using fs NodeJS command. But I need read those files with an external Window app. So I need those files in ANSI encode. I installed Wine and for now, I open the file with notepad and save it again to convert the codification. There is any way to generate the TXT files with ANSI encoding from NodeJS directly?


Solution

  • I solved my question like this:

    let txtContent = '' // string with content to save as file
    
    const buffer = Buffer.from(txtContent, 'latin1')
    fs.writeFile('files/file_name.txt')