title: Difference between readFileSync and using promisify on top of readFile with async/await
body: <p>Out of curiosity, i want to know if there is any difference between the two.</p>
  
  <p>readFileSync:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function parseFile(filePath) {
    let data = fs.readFileSync(filePath);
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>readFile with promisify: </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const readFilePromise = promisify(fs.readFile);
  async function parseFile(filePath) {
    let data = await readFilePromise(filePath);
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>If you need some context, im trying to read a bunch of files in a folder, replace a lot of values in each one, and write it again.</p>
  
  <p>I don`t know if there is any difference in using Asyncronous or Synchronous code for these actions.</p>
  
  <p>Full code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function parseFile(filePath) {
    let data = fs.readFileSync(filePath);
    let originalData = data.toString();
    let newData = replaceAll(originalData);
  
    return fs.writeFileSync(filePath, newData);
  }
  
  function readFiles(dirPath) {
    let dir = path.join(__dirname, dirPath);
    let files = fs.readdirSync(dir); // gives all the files
    files.map(file =&gt; parseFile(path.join(dir, file)));
  }
  
  function replaceAll(text) {
    text = text.replace(/a/g, 'b');
    return text;
  }
  
  readFiles('/files');</code></pre>
  </div>
  </div>
  </p>