title: Correct way to pass data from nodejs to angular in nwjs (node-webkit)
body: <p><strong>Solved: The below code now works for anyone who needs it.</strong>   </p>
  
  <ol>
  <li>Create an Angular factory that queries a database and returns query results.</li>
  <li>Pass those results of the query into the $scope of my controller</li>
  <li>Render the results of the $scope variable in my view (html)</li>
  </ol>
  
  <p><strong>Challenge:</strong>
  Because this is for a node-webkit (nwjs) app, I am trying to do this without using express, setting up api endpoints, and using the $http service to return the query results.  I feel like there should be a more eloquent way to do this by directly passing the data from nodejs to an angular controller.  Below is what I've attempted but it hasn't worked. </p>
  
  <p><strong>Database:</strong>  Below code is for a nedb database.</p>
  
  <p>My <strong>Updated</strong> Controllers</p>
  
  <pre><code>app.controller('homeCtrl', function($scope,homeFactory){
  
      homeFactory.getTitles().then(function(data){
          $scope.movieTitles = data;
      });
  });
  </code></pre>
  
  <p>My <strong>Updated</strong> Factory:</p>
  
  <pre><code>app.factory('homeFactory', function($http,$q) {
  
  return {
  
      getTitles: function () {
          var deferred = $q.defer();
          var allTitles = [];
  
          db.find({}, function (err, data) {
              for (var i = 0, len = data.length; i &lt; len; i++) {
                  allTitles.push(data[i].title)
              }
              deferred.resolve(allTitles);
          });
  
          return deferred.promise;
      }
  }
  </code></pre>
  
  <p>});</p>
  
  <p>HTML</p>
  
  <pre><code>   &lt;script&gt;
          var Datastore = require('nedb');
          var db = new Datastore({ filename: './model/movies.db', autoload: true });
      &lt;/script&gt;
  
  &lt;--shows up as an empty array--&gt;
  &lt;p ng-repeat="movie in movieTitles"&gt;{{movie}}&lt;/p&gt;
  </code></pre>