title: node.js: how to HTTP-get and decode/encode response in custom format
body: <p>This is the page which states which encodings are supported in node.js: <a href="https://nodejs.org/api/buffer.html#buffer_buffer" rel="nofollow noreferrer">here</a> or <a href="https://github.com/joyent/node/blob/5a5a98d0d8281f6901b7e9dac285d59ab3e39b95/lib/buffer.js#L126" rel="nofollow noreferrer">here</a>. Many of popular (or popular some time ago) encodings are missing, such as windows-1252.</p>
  
  <p>I want to fetch a webpage that is in windows-1252 and parse the response, finally, save it into a file. I'm having trouble with encoding. I've done lots of different tries and my mind is blowing up :(</p>
  
  <p>So I know there are <code>iconv</code> and <code>iconv-lite</code> modules in node.js that support more encodings than node.js does. I'd like to use <code>iconv-lite</code>, since I'm unable to compile stuff required for <code>iconv</code> on my company machine. Anyway, I've got</p>
  
  <pre><code>var iconv = require('iconv-lite');
  </code></pre>
  
  <p>Now, the difficult part - fetching the response. As I wrote, my resource lies somewhere in the web, so I need to fire a HTTP request. I've been trying node-wget (npm:<code>wget</code> module), <code>http.request</code>, <code>http.get</code> and all of those tries failed.</p>
  
  <p>I also googled and the closest solution to what I need seems to be <a href="https://stackoverflow.com/questions/12040643/nodejs-encoding-using-request">nodejs encoding using request</a> / <a href="https://stackoverflow.com/a/22027928/769384">https://stackoverflow.com/a/22027928/769384</a>, but the author didn't write what the hell is <code>request</code> there - is it a node module? How does he loads it?</p>
  
  <p>I've also read <a href="https://groups.google.com/forum/#!topic/nodejs/smA6-jGq2pw" rel="nofollow noreferrer">https://groups.google.com/forum/#!topic/nodejs/smA6-jGq2pw</a>, but found no clean solution there.</p>
  
  <p>I'd appreciate a minimal set of code that enabled me to fetch a web document and convert it on the fly from <code>windows-1252</code> encoding to <code>UTF-8</code>. The only parameter is the URL of the document.</p>