title: fetch JSON array from node to Reactjs
body: <p>I'm trying to fetch an array on my node server on <code>localhost:3000/users</code> to my react app on <code>localhost:3000</code>.
  The problem is I don't getting an array on react and cannot fetch anything to my list.</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  var arr = [{
    id: 1,
    username: "samsepi0l"
  }, {
    id: 2,
    username: "D0loresH4ze"
  }];
  
  /* GET users listing. */
  router.get('/', function(req, res, next) {
    // Comment out this line:
    //res.send('respond with a resource');
  
    // And insert something like this instead:
    res.json(arr);
  });
  
  module.exports = router;
  </code></pre>
  
  <p>And the react App.js</p>
  
  <pre><code>import React, { Component } from 'react';
  import logo from './logo.svg';
  import './App.css';
  
  class App extends Component {
    state = {users: []}
  
    componentDidMount() {
      fetch("/users")
        .then( (res) =&gt; res.json())   
        .then( (json) =&gt; {this.setState({users: json});});
    }
  
    render() {
      return (
        &lt;div className="App"&gt;
          &lt;h1&gt;Users&lt;/h1&gt;
          {this.state.users.map(user =&gt;
            &lt;div key={user.id}&gt;{user.username}&lt;/div&gt;
          )}
        &lt;/div&gt;
      );
    }
  }
  
  export default App;
  </code></pre>
  
  <p>How can I fetch the array to react page?</p>
  
  <p>and here is the error that I got when I run the npm server:
  Unhandled Rejection (SyntaxError): Unexpected token &lt; in JSON at position 0</p>