title: React.js reading from a local file
body: <p>I am currently using react with node js in my application. </p>
  
  <p>I am trying to read from a text file, get different errors when I try different things. With research, the easiest path to read from a file is using 'fs', so I'll post the two ways I tried to read from a local file (client side). </p>
  
  <p><strong>I would appreciate it if anyone could help solve my errors, or even show me a different way of reading from a local file!</strong> </p>
  
  <pre><code>import React ...
  import { readFile, readFileSync } from 'fs';
  // other imports
  
  class Background extends Component {
       // my constructor
  
       componentDidMount() {
           this.loadMe();
       }
  
       loadMe() {
            var file = './read_file';
  
            /* WAY 1: Asynchronously using readFile */
            readFile(file, function(err, data) {
                 if (err) { console.log(err) }
                 console.log(data);
            }
  
            /* WAY 2: Synchronously using readFileSync */
            var data = readFileSync(file);
            console.log(data);
       }
  }
  </code></pre>
  
  <p>Obviously, I am not running both ways at the same time. I also essentially copied the code from other stack overflow answers and some tutorials online. I looked into <code>FileReader</code> but couldn't make it work.</p>
  
  <p>The error I am currently receiving: <code>TypeError: Object(...) is not a function
  </code> pointing at <code>var data = readFileSync(file);</code></p>
  
  <p>Thank you!</p>