title: String of Binary to Buffer in Node.js
body: <p>I'm trying to convert a string of <code>0</code> and <code>1</code> into the equivalent <code>Buffer</code> by parsing the character stream as a UTF-16 encoding.</p>
  <p>For example:</p>
  <pre class="lang-js prettyprint-override"><code>var binary = &quot;01010101010101000100010&quot;
  </code></pre>
  <p>The result of that would be the following Buffer</p>
  <pre><code>&lt;Buffer 55 54&gt;
  </code></pre>
  <p>Please note <code>Buffer.from(string, &quot;binary&quot;)</code> is not valid as it creates a buffer where each individual <code>0</code> or <code>1</code> is parsed as it's own Latin One-Byte encoded string. From the Node.js documentation:</p>
  <blockquote>
  <p>'latin1': A way of encoding the Buffer into a one-byte encoded string (as defined by the IANA in RFC 1345, page 63, to be the Latin-1 supplement block and C0/C1 control codes).</p>
  <p>'binary': Alias for 'latin1'.</p>
  </blockquote>