title: Node.js how to read a file and then write the same file with two separate functions?
body: <p>What I want to do is read a file and then be able to perform other operations with that information as I write the file. For example:</p>
  
  <p>read file
  write file and at the same time perform MD5 hash, digital signing etc.</p>
  
  <p>I could use fs.readfile and fs.writefile as one operation and just copy the file from the web server to my computer, but I don't think I could still do these same operations. Anyway, skipping the in between stuff. How do I use fs.readfile and writefile to create two separate functions to copy a file? Here is what I have been working on, and yes I've read these forums extensively in search of an answer.</p>
  
  <pre><code>var fs = require('fs');
  
  
  
  function getData(srcPath) { 
  fs.readFile(srcPath, 'utf8', function (err, data) {
          if (err) throw err;
          return data;
          }
      );
  }
  
  
  function writeData(savPath, srcPath) {
          fs.writeFile (savPath, (getData(srcPath)), function(err) {
          if (err) throw err;
              console.log('complete');
          }
      );
  }
  //getData ('./test/test.txt');
  writeData ('./test/test1.txt','./test/test.txt');
  </code></pre>
  
  <p>I want to be able to download files of any type and just make raw copies, with md5 hash etc attached to a JSON file.  That will probably be a question for later though.</p>