title: TypeError: Net.createConnection is not a function`
body: <p>I'm trying to connect to a MySQL database using React and Node, and I created a database class to act as a singleton to get the connection to the database, but then it gives me the following error:</p>
  
  <p><code>TypeError: Net.createConnection is not a function</code></p>
  
  <p>I've done some searching and the main search results I can see are that the code is rendering client side, which doesn't completely make sense to me, considering I'm running this on node js through npm start.</p>
  
  <pre><code>    let con = null;
      class Database
      {
  
      }
      Database.prototype.connection = function()
      {
          if(con!=null) {
              return con;
          }
          var mysql = require('mysql');
          var con = mysql.createConnection({
              host: "localhost",
              user: "yourusername",
              password: "yourpassword"
          });
  
          con.connect(function(err) {
          if (err) throw err;
              console.log("Connected!");
          });
          return con;
      }
      export default Database;
  </code></pre>
  
  <p>I apologize if I don't know the correct terminology.</p>
  
  <p><a href="https://i.stack.imgur.com/nDvtJ.png" rel="nofollow noreferrer">Error I see in the browser</a></p>