user1354934
user1354934

Reputation: 8841

how to make an HTTP get request using nodejs HTTP?

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?

Upvotes: 0

Views: 197

Answers (1)

nvartolomei
nvartolomei

Reputation: 1505

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

Upvotes: 4

Related Questions