title: Can not complete GET request to my localhost or to my external API (express app)
body: <p>I am building a React app to consume an API that I built using express.js. My React app successfully gets data using fetch or axios to query data using an official API ("<a href="https://jsonplaceholder.typicode.com/users" rel="nofollow noreferrer">https://jsonplaceholder.typicode.com/users</a>"), but I keep getting an error when I try to get from my own API ("XXX.us-east-1.elasticbeanstalk.com/api/v1/users") or from my localhost ("<a href="http://localhost:81/api/v1/users" rel="nofollow noreferrer">http://localhost:81/api/v1/users</a>").</p>
  
  <p><strong>Questions</strong>
  Is my GET request wrong?
  Is there a problem with the return from my API?
  Would you recommend any resources to learn to create a RESTful API with Express.js, set it up in AWS and consume this API with a React app?</p>
  
  <p>Thank you!</p>
  
  <hr>
  
  <p>The error is:</p>
  
  <blockquote>
    <p>Access to fetch at 'XXX.us-east-1.elasticbeanstalk.com/api/v1/users' from origin '<a href="http://localhost:3000" rel="nofollow noreferrer">http://localhost:3000</a>' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled</p>
  </blockquote>
  
  <hr>
  
  <p>Using <code>fetch</code>:</p>
  
  <pre><code>componentDidMount() {
      fetch
        ('https://jsonplaceholder.typicode.com/posts/1')
        // ('XXX.us-east-1.elasticbeanstalk.com/api/v1/users')
        // ('http://localhost:81/api/v1/users')
        .then(response =&gt; response.json())
        .then(data =&gt;
          this.setState({
            title: data.title,
            body: data.body
          })
        );
    }
  </code></pre>
  
  <p>Using <code>axios</code>:</p>
  
  <pre><code>componentDidMount() {
      axios
        .get('https://jsonplaceholder.typicode.com/users').then(res =&gt; this.setState({ users: res.data }))
     // .get('http://localhost:81/api/v1/users', { crossDomain: true }).then(res =&gt; this.setState({ users: res.data }))
        .catch(function (error) {
          console.log("Error");
        });
    }
  </code></pre>