title: How to resolve 'Error: connect ECONNREFUSED 127.0.0.1:9200' using ElasticSearch with Firebase?
body: <p>I know that this question has been asked several times, but the solutions didn't apply to my situation. I have started <code>ElasticSearch</code>, <code>Kibana</code> using these 2 commands:</p>
  
  <pre><code>bin/elasticsearch
  bin/kibana
  </code></pre>
  
  <p>And the server is running well, when using browser to go to <code>http://localhost:9200</code>, I get the following result:</p>
  
  <pre><code>{
      "name" : "vg7RnLh",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "gqDf0H67TxGZGYigAlu2mQ",
      "version" : {
          "number" : "6.1.2",
          "build_hash" : "5b1fea5",
          "build_date" : "2018-01-10T02:35:59.208Z",
          "build_snapshot" : false,
          "lucene_version" : "7.1.0",
          "minimum_wire_compatibility_version" : "5.6.0",
          "minimum_index_compatibility_version" : "5.0.0"
      },
      "tagline" : "You Know, for Search"
  }
  </code></pre>
  
  <p>And when using <code>kibana</code>, everything works fine. Here is the firebase cloud function I wrote, if there's anything wrong, I think it's here:</p>
  
  <pre><code>exports.downloadUserInfo = functions.https.onRequest((req, res) =&gt; {
      const { uid } = req.query;
  
      const searchConfig = {
          uri: 'http://localhost:9200/users/user/' + uid,
          method: 'GET'
      };
  
      request(searchConfig)
          .then((result) =&gt; {
             console.log(result);
             return res.status(200).send(result);
         })
             .catch((error) =&gt; {
                 console.log(error);
                 return res.status(400).send(error);
             });
  });
  </code></pre>
  
  <p>Where <code>request</code> is a module install by <code>yarn add request request-promise</code>. Then, when using <code>Postman</code> to test my API, I get this error:</p>
  
  <p><a href="https://i.stack.imgur.com/bSYqG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bSYqG.png" alt="enter image description here"></a></p>
  
  <p>How do I resolve this?</p>
  
  <p><strong>Update</strong></p>
  
  <p>I am also running <code>flashlight</code> using command <code>node app.js</code>. When inserting a new user to the database, the new user is automatically inserted to the ElasticSearch server too (localhost), however, when I try to read, it throws request error</p>
  
  <p><strong>Second Update</strong></p>
  
  <p>This is the API that creates a user:</p>
  
  <pre><code>exports.register = functions.https.onRequest((req, res) =&gt; {
      const { firstName, lastName } = req.body;
  
      admin.database().ref('users').push({ firstName, lastName })
          .then(() =&gt; res.status(201).send())
          .catch(() =&gt; res.status(400).send());
  });
  </code></pre>
  
  <p>When a new user is created by this API, this user is automatically inserted to my localhost ElasticSearch server, because I am using <code>flashlight</code> plugin. I don't understand why when I try to read from the same server, there's request error.</p>