title: How can I Fetch and display Mysql data into ReactJS front end with Node JS as backend?
body: <p>Trying to figure out on how to fetch data from mysql and display it in ReactJS. I'm using NodeJS on the backend along with express. I tried a code snippet found on the internet but it doesn't work as it is expected. </p>
  
  <p>Here's what i get when i run the react app.</p>
  
  <pre><code>TypeError: http.ServerResponse is undefined
  </code></pre>
  
  <p>My NodeJS code</p>
  
  <pre><code>//require mysql, http and express
  //const connection = createConnection({with host, user, pass, db});
  const app = express();
  app.get('/posts', function(request, result){
      connection.connect();
      connection.query("SELECT * FROM 'some_table';", function(err, results, fields){
           if(err) throw err;
          result.send(results);
      })
      connection.end();
  })
  app.listen(3000);
  </code></pre>
  
  <p>My React code</p>
  
  <pre><code>class Display extends React.Component{
      constructor(props){
          super(props);
          this.state={ posts : [] };
  
          fetch('http://localhost:3000/posts/')
              .then(response =&gt;{
                  response.json();
              })
              .then(posts =&gt; {
                  this.setState({posts})
              })
              .then( (err) =&gt; {
                  console.log(err);
              })
      }
      render(){
          return(
              &lt;div&gt;
                  &lt;ul&gt;
                      {this.state.posts.map( post =&gt; 
                      &lt;p&gt;
                          &lt;li&gt;Some Text_1: {post.db_col_1}&lt;/li&gt;
                          &lt;li&gt;Some Text_2: {post.db_col_2}&lt;/li&gt;
                          &lt;li&gt;Some Text_3: {post.db_col_3}&lt;/li&gt;
                      &lt;/p&gt;
                      )}
                  &lt;/ul&gt;
              &lt;/div&gt;
          )
      }
  }
  export default Display;
  </code></pre>