title: Node.JS "Uncaught TypeError: util.TextEncoder is not a constructor"
body: <p>I have used browserify to bundle up my js files. I get an error of the form</p>
  <pre><code>Uncaught TypeError: util.TextEncoder is not a constructor
      at Object.1.util (bundle.js:3)
      at o (bundle.js:1)
      at r (bundle.js:1)
      at bundle.js:1
  </code></pre>
  <p>Here are my initial few lines of bundle.js</p>
  <pre><code>(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c=&quot;function&quot;==typeof require&amp;&amp;require;if(!f&amp;&amp;c)return c(i,!0);if(u)return u(i,!0);var a=new Error(&quot;Cannot find module '&quot;+i+&quot;'&quot;);throw a.code=&quot;MODULE_NOT_FOUND&quot;,a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u=&quot;function&quot;==typeof require&amp;&amp;require,i=0;i&lt;t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
  var util = require('util');
  var utf8 = new util.TextEncoder();
  
  let secretDataTxt=document.querySelector(`#SecretData`);
  let passwordTxt=document.querySelector(`#Password`);
  let result=document.querySelector(`#Result`);
  
  let encryptBtn=document.querySelector(`#encrypt`);
  </code></pre>
  <p>Can someone please help me with this error?</p>
  <p>EDIT: Here is a working example</p>
  <pre><code>const util = require('util');
  const utf8 = new util.TextEncoder();
  
  console.log(utf8.encode(&quot;Hello&quot;));
  </code></pre>
  <p>Output: Uint8Array(5) [ 72, 101, 108, 108, 111 ]</p>