title: NodeJS HTML: 'require' is undefined
body: <p>I've been working on a NodeJS login/register script (called LoginRegister.js) that seemed to work fine in the terminal. I've also installed NodeJS, and the bcrypt module for it. Here's the file:</p>
  
  <pre><code>// Initialization
  var fs = require("fs");
  var bcrypt = require("bcrypt");
  var LUinputID = $("#LUsernameIn").value;
  var LPinputID = $("#LPasswordIn").value;
  var RUinputID = $("#RUsernameIn").value;
  var RPinputID = $("#RPasswordIn").value;
  
  var UserStorageTextFile = "Users.txt";
  
  $(document).ready(function(){
      console.log("Hello");
      var RButton = $("rBTN").addEventListener("click", registerUser(UserStorageTextFile, RUinputID, RPinputID));
      var LButton = $("#lBTN").addEventListener("click", registerUser(UserStorageTextFile, LUinputID, LPinputID));
  });
  
  // Defining Functions
  function encrypt(passwordFromUser) {
      var salt = bcrypt.genSaltSync(10);
      var hash = bcrypt.hashSync(passwordFromUser, salt);
      return hash;
  }
  
  function passCheck(passwordFromUser, passHashed){
      return bcrypt.compareSync(passwordFromUser,passHashed);
  }
  
  function loginUser(usersTextFile, username, password){
      data = fs.readFileSync(usersTextFile).toString();
  
      if(data.indexOf(username) != -1){
          console.log(data.indexOf(username));
          for (var i = 0; i &lt;= data.indexOf(username); i++) {
              if (i == data.indexOf(username)) {
                  i += (username.length + 1);
                  passcode = data.slice(i, i+60);
  
                  if (passCheck(password, passcode)) {
                      console.log("Yes!!");
                  }
                  else{
                      console.log("No!!");
                  }
              }
          }
      }
      else{
          console.log("No!!");
      }
  }
  
  function registerUser(usersTextFile, username, password) {
      data = fs.readFileSync(usersTextFile);
      saveData = data + username + "-" + encrypt(password) + "\n";
  
      fs.writeFile('Users.txt', saveData, (err2) =&gt; {
          console.log("User " + username + " Registered!");
      });
  }
  </code></pre>
  
  <p>I wanted to test it in a browser, so I put together an html file to display my JS one in action:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Authentication Test&lt;/title&gt;
      &lt;script src="http://code.jquery.com/jquery-1.9.1.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="LoginRegister.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;h2&gt;Login&lt;/h2&gt;
  &lt;input type="text" id="RUsernameIn"&gt;
  &lt;input type="password" id="RPasswordIn"&gt;
  &lt;button id="lBTN"&gt;Login&lt;/button&gt;
  
  &lt;h2&gt;Register&lt;/h2&gt;
  &lt;input type="text" id="LUsernameIn"&gt;
  &lt;input type="password" id="LPasswordIn"&gt;
  &lt;button id="rBTN"&gt;Register&lt;/button&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>I opened up the HTML file in Microsoft Edge and tried pressing the register button after putting in details into the boxes, but I checked the Users.txt file and nothing had happened. After looking at the F12 Developer Tools, I noticed that on startup, the console stated:</p>
  
  <pre><code>SCRIPT5009: 'require' is undefined
  LoginRegister.js (2,1)
  </code></pre>