title: Parent function returning a JSON object from a nested function
body: <p>So I'm trying to create a function that returns a JSON object that is read from a file, however, I don't know how to return the object from the <code>readConfig</code> function. I tried to create a callback function but was unable to do so. I know the function works because when I <code>console.log(jsonData)</code> from inside the <code>readFile.then()</code>, it logs the object correctly.</p>
  <pre><code>const fs = require('node:fs')
  
  function readConfig() {
      fs.promises.readFile('./config.json', 'utf8')
          .then(content =&gt; {
              jsonData = JSON.parse(content, null, 2);
              return jsonData
          })
          .catch(err =&gt; {
              console.log(err);
          });
  };
  
  
  // This is what I want to do able to do with the readConfig function
  
  data = readConfig()
  console.log(data.value)
  </code></pre>
  <p>Any help is greatly appreciated :)</p>
  <p>EDIT:
  I tried using the promise based return that was commented but would just get promises returned back.</p>
  <pre><code>const fs = require('node:fs')
  
  function readConfig() {
      return fs.promises.readFile('./config.json', 'utf8')
          .then(content =&gt; {
              jsonData = JSON.parse(content, null, 2);
              return jsonData
          })
          .catch(err =&gt; {
              console.log(err);
          });
  };
  
  readConfig().then(v =&gt; v);
  </code></pre>
  <p>However this just returns back a pending promise, I want to be able to access the values of the JSON object.
  What I want to be able to do is;
  <code>readConfig().value</code>
  and access a value from the object but can't get this to work.
  I just want to be able to access multiple values from this object in a simple way</p>