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?

2
  • Duplicate of this Commented Jan 1, 2016 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) Commented Jan 1, 2016 at 14:31

1 Answer 1

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. 
  }
})
Sign up to request clarification or add additional context in comments.

2 Comments

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 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.