Reputation: 2620
I am new to nodejs and express. I am using "request" library to read content of google.com. I keep getting connection refused error. I took the code from https://github.com/request/request
This is my first_request.js file:
var request = require('request');
request('http://www.google.com', function (error, response, body) {
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the HTML for the Google homepage.
});
To run, I got to the folder and do node first_request.js
it give me error as:
What am I doing wrong? Any pointers?
Upvotes: 2
Views: 763
Reputation: 2826
This error occurs when you have a proxy set up. The link works fine on my computer. You can set your proxy options with request.defaults({})
. You should specify user credentials + host and port.
var request = require('request');
var link = "http://www.google.com";
var proxyUrl = "http://" + user + ":" + password + "@" + host + ":" + port;
var proxiedRequest = request.defaults({'proxy': proxyUrl});
proxiedRequest(link , function (error, response, body) {
//handle the response..
})
Upvotes: 2