How to make external HTTP requests with Node.js ?

+1 vote
I want to use a Node.js server as a proxy to log, authenticate, and forward HTTP queries to a backend HTTP server (PUT, GET, and DELETE requests).

What library should I use for that purpose?
Oct 11 in Node-js by kartik
• 35,720 points
35 views

1 answer to this question.

0 votes

Hello @kartik,

Use this:

var http = require('http');

var options = {
  host: 'example.com',
  port: 80,
  path: '/foo.html'
};

http.get(options, function(resp){
  resp.on('data', function(chunk){
    //do something with chunk
  });
}).on("error", function(e){
  console.log("Got error: " + e.message);
});

Hope it helps!!
Thank you!!

answered Oct 11 by Niroj
• 77,920 points

Related Questions In Node-js

0 votes
1 answer

How can I use an http proxy with node.js http.Client?

Hello @kartik, You can use request, I just found ...READ MORE

answered Jul 17 in Node-js by Niroj
• 77,920 points
993 views
0 votes
1 answer

How to execute an external program from within Node.js?

Hello @kartik, Exec has memory limitation of buffer ...READ MORE

answered Jul 17 in Node-js by Niroj
• 77,920 points
398 views
0 votes
1 answer

How to make connection to Postgres via Node.js?

Hello @kartik, Here is an example I used ...READ MORE

answered Jul 17 in Node-js by Niroj
• 77,920 points
101 views
0 votes
1 answer

How to use MongoDB with promises in Node.js?

Hello @kartik, Try this: var MongoClient = require('mongodb').MongoClient var url ...READ MORE

answered Oct 11 in Node-js by Niroj
• 77,920 points
46 views
0 votes
1 answer

jQuery AJAX fires error callback on window unload - how do I filter out unload and only catch real errors?

Hello, In the error callback or $.ajax you have three ...READ MORE

answered Apr 27 in Java-Script by Niroj
• 77,920 points
448 views
0 votes
1 answer

How do I pass command line arguments to a Node.js program?

Hello @kartik, If your script is called myScript.js ...READ MORE

answered May 5 in Java-Script by Niroj
• 77,920 points
696 views
0 votes
1 answer

Error:Issue when trying to use IN() in wordpress database

Hello @kartik, Try this code : // Create an ...READ MORE

answered May 8 in PHP by Niroj
• 77,920 points
91 views
+2 votes
1 answer

How do I debug Node.js applications?

Hello @kartik, Use node-inspector  from any browser supporting WebSocket. Breakpoints, ...READ MORE

answered Jul 8 in Node-js by Niroj
• 77,920 points
87 views
0 votes
1 answer

How do I get the path to the current script with Node.js?

Hello @kartik, you can do this: fs.readFile(path.resolve(__dirname, 'settings.json'), 'UTF-8', ...READ MORE

answered Jul 8 in Node-js by Niroj
• 77,920 points
546 views
0 votes
1 answer

How to paginate with Mongoose in Node.js?

Hello @kartik, You can chain just like that: var ...READ MORE

answered Jul 15 in Node-js by Niroj
• 77,920 points
63 views