title: Changes don't occur because of node.js' asynchronicity
body: <p>I'm a beginner at node js and I'm doing a simple project with pure node.js.
  So here is my code:</p>
  
  <pre><code>if(req.url ==="/"&amp;&amp;req.method==="POST"){
          let reqBody = "";
          req.on('data', chunk=&gt;{
              reqBody += chunk.toString();
          });
          req.on("end", ()=&gt;{
              reqBody = reqBody.split("&amp;");
              for(let i=0; i&lt;reqBody.length; i++){
                  reqBody[i]=reqBody[i].split("=");
                  reqBody[i] = reqBody[i][1];
                  };
              //filter country    
              let countryFound;
              if(reqBody[1].length&gt;0){
                      let countryList = "";
                      let countryVal = [];
  
                      countryListStream = fs.createReadStream("./public/country.list.json", "UTF-8");
                      countryListStream.on("data", countryChunk=&gt;{
                          countryList+=countryChunk;
                          countryChunk = JSON.parse(countryChunk);
                          countryFound = countryChunk.filter(elem=&gt; elem["name"].toLowerCase()==reqBody[1].toLowerCase());
                          if(countryFound.length!==0){
                              countryListStream.destroy();
                          };
                      });
                      countryListStream.on("end", ()=&gt;{
                          countryFound = "Not Found"
                      });
              };
          });
  
      };
  </code></pre>
  
  <p>My problem is below "filter country" comment:
  when I log the "countryFound" variable outside of the events of "countryListStream", it displays undefined.But when i log it inside of the events, it displays what I want. I think it's becaus of how node.js is made, but I don't know to continue my code if it's undefined.
  I think that I need to include a code that waits until the variable is updated, and then it runs the rest.
  I tried with this after the if statement, and it didn't fixed it:</p>
  
  <pre><code>if(countryFound!===undefined){
      console.log(countryFound);
  }
  </code></pre>