title: Get value form REST API using function
body: <p>I am trying to create a function that return a REST API response using nodeJS and express, request.
  This is a snippet of my code:</p>
  
  <pre><code>var express = require('express')
  var httpRequest = require('request');
  var bodyParser = require('body-parser');
  var app = express() 
  
  function getData1() {
  
      request('http://www.my-server.com/data', function (error, response, body) {
        if (!error &amp;&amp; response.statusCode == 200) {
          return body;
        }
      })
  } 
  
  app.get('/get-data', function (request, response) {
      var data1 = getData1();
  
      //do something with data
  
  
    response.send(data1);
  });
  </code></pre>
  
  <p>Would you have any idea how I can do ?</p>
  
  <p>Best regards</p>