title: How to make external API call to Yelp in Node.js/Express/Angular app
body: <p>I am trying to make an API call to Yelp in my Node.js app. I saw from here that I should use this code in order to be able to use the Yelp API: <a href="https://arian.io/how-to-use-yelps-api-with-node/" rel="nofollow">https://arian.io/how-to-use-yelps-api-with-node/</a> . I used that code in my app.js file. Now in order for it to display the results on the browser I know that I have to connect the controller to the view (in my case index.html) and bind the two files with $scope. But I would also have to somehow connect the controller to app.js. The tutorial that I followed on arian.io said: </p>
  
  <blockquote>
    <p>Now if you call the function request_yelp(params, callback) it will call the callback with these arguments, callback(error, response, body).
     That's it, now you're ready to take full advantage Yelp's API.</p>
  </blockquote>
  
  <p>but how or where do I call that function? I assume I'd do it in my controller but I have tried that but it didn't work. </p>
  
  <p>To summarize my issue, if the API call is right and it is where it should be, then my next step is to link that with my controller, once those two are connected, I have to bind html with apiController.js with $scope in order to bring my data results to be displayed in the browser. I know I am missing a lot of things, but I think I have the right idea.  </p>
  
  <p>Any help is welcome. Thanks!</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>   My app's tree 
  
  &gt;.git
  &gt;bower_components
  &gt;client
      &gt;controllers
          -apiControllers   (My one and only controller)
      &gt;css
      &gt;views               (This is empty)
      app.js
      index.html (This is my one and only page/ my app is a one page app)
      package.json
  &gt;models
  &gt;node_modules
  app.js    (This is where I am trying to make the API call)
  
  
  &lt;-- ================================================== --&gt;
  
   //This is my app.js file
  
  
      //Call packages needed
      var express = require('express');
      var app = express();                   
      var bodyParser = require('body-parser');
      var mongoose = require('mongoose');
      var dotenv = require('dotenv').config();
      var oauthSignature = require('oauth-signature');
      var n = require('nonce')();
      var request = require('request');
      var qs = require('querystring');
      var _ = require('lodash');
  
      // Function for yelp call
      var request_yelp = function(set_parameters, callback) {
  
        var httpMethod = 'GET';
  
        var url = 'http://api.yelp.com/v2/search';
  
        var default_parameters = {
          location: 'New+York',
          sort: '2'
        };
  
        var required_parameters = {
          oauth_consumer_key : process.env.yelp_consumer_key,
          oauth_token : process.env.yelp_token,
          oauth_nonce : n(),
          oauth_timestamp : n().toString().substr(0,10),
          oauth_signature_method : 'HMAC-SHA1',
          oauth_version : '1.0'
        };
  
        var parameters = _.assign(default_parameters, set_parameters, required_parameters);
  
        var consumerSecret = process.env.yelp_consumer_secret;
        var tokenSecret = process.env.yelp_token_secret;
  
        var signature = oauthSignature.generate(httpMethod, url, parameters, consumerSecret, tokenSecret, { encodeSignature: false});
  
        parameters.oauth_signature = signature;
  
        var paramURL = qs.stringify(parameters);
  
        var apiURL = url+'?'+paramURL;
  
        request(apiURL, function(error, response, body){
          return callback(error, response, body);
        });
  
      };
  
      app.use(express.static(__dirname+'/client'));
  
      app.get('/', function request_yelp(params, callback){
          res.send('This is the main page');
      });
  
      app.listen(3000);
      console.log('Running on port 3000');
  
  
  &lt;-- ================================================== --&gt;
  &lt;!-- This is index.html. Here I would like to display my YELP responses. I am using Bootstrap
  
  &lt;div class="container-fluid"&gt;
    &lt;div class="row-fluid"&gt;
        &lt;!-- &lt;div class="container-fluid"&gt; --&gt;
        &lt;!-- &lt;div class="jumbotron"&gt; --&gt;
                    &lt;div class="row-fluid"&gt;
                        &lt;!-- &lt;div ng-controller="MainCtrl"&gt; --&gt;
                              &lt;p&gt;&lt;date-input name="info.name" message="info.message"&gt;&lt;/date-input&gt;&lt;/p&gt;
                  &lt;div data-ng-repeat="business in businesses"&gt;
                               &lt;!-- &lt;div class="col-lg-offset-1"&gt; --&gt;
                              &lt;div class="col-lg-2 col-lg-offset-2 col-md-3 col-sm-2 col-xs-6 text-center"&gt;
                                      &lt;p&gt;Breakfast&lt;/p&gt;
                                  &lt;div class="thumbnail"&gt;
                                      &lt;img class="img-responsive img-circle" src="{{business.image_url}}"&gt;
                                      &lt;h5&gt;{{business.name}}&lt;/h5&gt;
                                      &lt;h5&gt;{{business.rating}}&lt;/h5&gt;
                                      &lt;h5&gt;"{{business.snippet_text}}"&lt;/h5&gt;
                                      &lt;h5&gt;{{business.categories[0]}}&lt;/h5&gt;
                                      &lt;p&gt;&lt;a class="btn btn-link btn-sm" href="{{business.url}}"&gt;View details &amp;raquo;&lt;/a&gt;&lt;/p&gt;
                                      &lt;p&gt;&lt;a class="btn btn-xs btn-info" id="breakfast" role="button" onClick="refreshPage()"&gt;I don't like this one!&lt;/a&gt;&lt;/p&gt;
                                  &lt;/div&gt;&lt;!-- End thumbnail --&gt;
                              &lt;/div&gt;&lt;!-- End col-md-4 --&gt;
  
  
  &lt;-- ================================================== --&gt;
  
  // Finally this is my apiController.js. What code do I need here to connect the API call to my view? 
  
  var myApp = angular.module('myApp', []);
  
  myApp.controller('MainCtrl', ['$scope'function($scope) {
      $scope.total = [];
      $scope.businesses = [];
  
  }])</code></pre>
  </div>
  </div>
  </p>