NodeJS express make get request

Issue

Is there a possibility to use express as a client-module, to make http-requests to another server?

At the moment I make requests this way:

var req = http.get({host, path}, function(res) {
    res.on('data', function(chunk) {
        ....
    }
}

This is too bulky. Express as server-module is very comfortable to use. I guess there’s a simple way to make a get-request by using express. I don’t like the express api, and I didn’t find anything there.

Solution

If you want simple requests, don’t use the express module, but for example request :

var request = require('request');
request('http://www.google.com', function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body) // Print the google web page.
  }
})

Answered By – Denys Séguret

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published