marcel marcel - 1 year ago 147
Javascript Question

NodeJS express make get request

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.

Answer Source

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

var request = require('request');
request('', function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body) // Print the google web page.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download