title: why is var mysql = require('mysql'); returning undefined
body: <p>EDITED:</p>
  
  <p>I am working on a page that takes the information a user enters into a form and adds it to a database. I created the database with mysql. When trying to connect to my database using javascript. My code breaks on <code>var mysql = require('mysql');</code>:</p>
  
  <p>I realized that this may be due to either the code being ran in a function or having the DOM related code in the function... </p>
  
  <p>I tried running a simple version of the code without those elements and it works to connect to and update the database but I need to be able to pull the values from the form so I am still struggling with how to do this. </p>
  
  <pre class="lang-js prettyprint-override"><code>function saveUserForm() {
      var firstName = document.getElementById("firstName");
      var lastName = document.getElementById("lastName");
      var psw = document.getElementById("psw");
      var userName = document.getElementById("userName");
      var email = document.getElementById("inputText");
      alert('test');
      var mysql = require('mysql');
      alert("mysql test");
      var con = mysql.createConnection({
        host: "localhost",
        user: "root",
        password: "abc123",
        database: "PBSC_Parking_DB"
      });
  
      con.connect(function(err) {
       if (err){
           throw err;
           alert("error");
       }
  
      var sql = "INSERT INTO accounts (UserName, FirstName, LastName, Email, UserPassword) VALUES ('"+userName+ "', '"+firstName+"','"+lastName+"','"+email+"','"+psw+"')";
  
        con.query(sql, function (err, result) {
          if (err) {
              throw err;
              alert("test error");
          }
          alert("account added");
          console.log(result.affectedRows + " record(s) updated");
        });
      }); 
  } 
  </code></pre>