0

I am getting a reference error because I cannot use XMLHttpRequest.

Is there a way to make a get http request to grab all the data from my mongodb?

GET from http://localhost:3000/api/v1/posts?

user1354934
  • 8,139
  • 15
  • 50
  • 80
  • Duplicate of [this](http://stackoverflow.com/questions/7967037/how-to-make-external-http-requests-with-node-js) – UtsavShah Jan 01 '16 at 14:10
  • How do I store the chunk that is returned? I want to be able to do Object.keys(the data).map(some function) – user1354934 Jan 01 '16 at 14:31

1 Answers1

4

You can try using this package https://www.npmjs.com/package/request

var request = require('request');
request('http://www.google.com', function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body) // Show the HTML for the Google homepage. 
  }
})
nvartolomei
  • 1,505
  • 12
  • 15
  • thank you my friend. however, just one question. I am receiving errors after doing the npm install, and after running my server - it is ssaying that it cannot find modules 'net' and 'tls'. What to do? Are these required? It is returning my JSON data, but throwing these errors into my console. – user1354934 Jan 01 '16 at 14:36
  • @user1354934 I'm not sure about this, just tried to install this package and created a simple file with example I posted and everything works great. – nvartolomei Jan 01 '16 at 15:14