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

0 votes
I want to make an outgoing HTTP call from node.js, using the standard http.Client. But I cannot reach the remote server directly from my network and need to go through a proxy.

How do I tell node.js to use the proxy?
Jul 17, 2020 in Node-js by kartik
• 37,510 points
9,980 views

1 answer to this question.

0 votes

Hello @kartik,

You can use request, I just found it's unbelievably easy to use proxy on node.js, just with one external "proxy" parameter, even more it supports HTTPS through a http proxy.

var request = require('request');

request({
  'url':'https://anysite.you.want/sub/sub',
  'method': "GET",
  'proxy':'http://yourproxy:8087'
},function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body);
  }
})

Hope it helps!!

Get your Node.js Certification today to become a certified expert.

Thank you!!

answered Jul 17, 2020 by Niroj
• 82,880 points

Related Questions In Node-js

0 votes
1 answer

How do I determine the current operating system with Node.js

Hello @kartik, With Node.js v6 (and above) there ...READ MORE

answered Jul 14, 2020 in Node-js by Niroj
• 82,880 points
3,434 views
0 votes
1 answer

How can i get the extension of the image in node.js?

Hello @kar You can do the following to ...READ MORE

answered Jul 16, 2020 in Node-js by Niroj
• 82,880 points
1,803 views
0 votes
1 answer

How is an HTTP POST request made in node.js?

Hello @kartik, A easier way if you use ...READ MORE

answered Jul 20, 2020 in Node-js by Niroj
• 82,880 points
652 views
0 votes
1 answer

How do I determine the current operating system with Node.js?

Hello @kartik, With Node.js v6 (and above) there ...READ MORE

answered Jul 20, 2020 in Node-js by Niroj
• 82,880 points
452 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, 2020 in Java-Script by Niroj
• 82,880 points
3,721 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, 2020 in Java-Script by Niroj
• 82,880 points
2,930 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, 2020 in PHP by Niroj
• 82,880 points
837 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, 2020 in Node-js by Niroj
• 82,880 points
776 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, 2020 in Node-js by Niroj
• 82,880 points
2,469 views
0 votes
1 answer

How can I pretty-print JSON using node.js?

Hello @kartik, JSON.stringify's third parameter defines white-space insertion ...READ MORE

answered Jul 12, 2020 in Node-js by Niroj
• 82,880 points
4,767 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP