Decode special cyrillic characters Decode special cyrillic characters curl curl

Decode special cyrillic characters


The website you request uses Windows-1251 encoding, which is not supported by NodeJS out of the box:

<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />

Browsers are smart enough to detect that and interpret correctly, apart from cURL and raw NodeJS requester. So, basically, you'll need a third-party module to convert the encoding, for example, iconv-lite:

const http = require("http");const iconv = require("iconv-lite");http.get("http://www.pravda.com.ua/news/2017/10/6/7157464/", (res) => {  res.pipe(iconv.decodeStream("win1251")).collect((err, body) => {    if (err) throw err;    console.log(body);  })});

In this snippet here I'm piping the response to the iconv-lite Transform stream, which does all the dirty work.