title: Javascript function with request not returning correct value
body: <p>I'm making a node app right now using the <code>request</code> node package to connect to APIs. When I make an API request however, the function to determine the validity of a <code>username</code> and <code>password</code> does not return <code>true</code> as expected. </p>
  
  <p>Here's my code so far:</p>
  
  <pre><code>const request = require("request")
  const API_URL = &lt;the_api_url&gt;
  
  const isValidLogin = (username, password) =&gt; {
      let success = false;
      let options = {
          url: API_URL,
          method: 'GET',
          auth: {
              user: username,
              pass: password
          }
      }
      request(options, (error, response, body) =&gt; {
          console.log(response.statusCode);
          if (error) {
              console.log(error)
          }
          if (response.statusCode == 200) {
              success = true;
          }
          else {
              success = false
          }
      })
      console.log(success)
      return success;
  }
  </code></pre>
  
  <p>When I pass in an invalid <code>username</code> and <code>password</code> to <code>isValidLogin()</code>, it correctly returns false. I do notice that the <code>response.statusCode</code> is <code>200</code> which should mean that <code>success</code> is <code>true</code> however it is not working as expected.</p>