title: Node.js asynchronous functions not working
body: <p>I have a function (lets call it f1) that calls another function (lets call it f2) inside it. The issue is that f2 is supposed to return a parsed json file output. But it always return undefined.</p>
  <pre><code>async function f1(){
      var customerDataArray = []
      fs.readdirSync(jsonFolder).forEach(file =&gt; {
          var temp = path.extname(file)
          if (temp == '.json'){
              customerDataArray.push(file)
          }
      });
      
      let templateFiles = customerDataArray
      console.log(templateFiles)
      
      for(let tfc=0; tfc &lt; templateFiles.length ; tfc++){
          let fileName = templateFiles[tfc]
          let filePath = './fashion/test/' + fileName
          const templateJSON = await f2(filePath)
          console.log(templateJSON)
      }
  
      console.log(templateJSON)
  }
  
  async function f2(filePath) {
      fs.readFile(filePath, &quot;utf8&quot;, (err, jsonString) =&gt; {
          if (err) {
            console.log(&quot;Error reading file from disk:&quot;, err);
            return;
          }
          try {
            const customer = JSON.parse(jsonString);
            return customer
          } catch (err) {
            console.log(&quot;Error parsing JSON string:&quot;, err);
          }
        });
    }
  </code></pre>
  <p>You can ignore the other details of the file. I am able to display the parsed file in f2 using console.log(customer). But when it is returned to f1, temmplateJSON is undefined.</p>
  <p>Any help is appreciated!</p>