title: How to correctly call fs.writeFile
body: <p>I can't figure out how to write on a JSON file.
  I'm working on a Single Application Page, using mostly AngularJS and Node.js</p>
  
  <p>This is my code:</p>
  
  <p>--index.html-- </p>
  
  <pre><code>&lt;script type="text/ng-template" id="pages/Animazione.html"&gt;
      ...
      &lt;td&gt;&lt;input id="clickMe" type="button" value="clickme" ng-click="doPost()" /&gt;&lt;/td&gt;
  </code></pre>
  
  <p>--app.js--</p>
  
  <pre><code>var App = angular.module('myMovie', ['ngRoute']);
  ...
  .when('/Animazione', {
          templateUrl : 'pages/Animazione.html',
          controller  : 'AnimazioneController'}
       )
  ...
  App.controller('AnimazioneController', ['$scope','$http', function($scope, $http) {
  
                      $http.get('Animazione.json').success(function(response)
                      {
                          $scope.myData=response;
                      })
                      .error(function()
                      { 
                          alert("Si è verificato un errore!"); 
                      });
  
  
                      $scope.doPost = function()
                  {
                      writeOutputFile({test: 1});
                  };
  
  
  }]);
  </code></pre>
  
  <p>--index.js-- (Server)</p>
  
  <pre><code>function writeOutputFile(data, success, fail) {
    var fs = require('fs');
    fs.writeFile('auth.json', JSON.stringify(data), function(error) {
      if(error) { 
        console.log('[write output]: ' + err);
          if (fail)
            fail(error);
      } else {
        console.log('[write output]: success');
          if (success)
            success();
      }
    });
  }
  </code></pre>
  
  <p>Is there any call or any function that I'm doing wrong?</p>