-2

Hi i need some help for this issue, I need to run:

 exports.someFunction = function () {
   // i need call a route like this.
   app.route('api/getdata');
};

I need call some route in express function. How can I do it?

techraf
  • 64,883
  • 27
  • 193
  • 198
Hiro Palacios
  • 103
  • 1
  • 1
  • 4

1 Answers1

0

I'm assuming that /api/getdata returns some sort of data (in a format like JSON) you need to use. In that case, it is pretty simple, just use Node's excellent unirest library. I find Node's http a little advanced for this case. Assuming that this is a GET request, it would look something along the lines of:

unirest.post('http://example.com/api/getdata').end(function (response) {
  console.log(response.body);
});

Of course, you can use Node's http.get if you wanted or any other HTTP library you like.

James Parsons
  • 6,097
  • 12
  • 68
  • 108