Is it possible to specify a port number when making at HTTP request using the request module? I'm not seeing anything about this in the documentation:
var request = require('request');
// this works
request({
method: 'GET',
url: 'http://example.com'
}, function(error, response, body) {
if (error) console.log(error);
console.log(body);
});
// this does not work
request({
method: 'GET',
url: 'http://example.com:10080'
}, function(error, response, body) {
// ...
});
Additionally, when I run the second version, absolutely nothing happens in my program (almost like the request was never made).
I also know that I can specify a port number when making a request using the core http
module. Why is the not an option in the request module?
EDIT: I should have mentioned this before, but I am running this application on Heroku.
When I run the request locally (using the request module) I am able to specify the port number, and get a successful callback.
When I run the request from Heroku, no callback is fired, and nginx shows no record of the request.
Am I crazy? Is there some reason Heroku is preventing me from making an outbound HTTP request to a specific port number?
Using
request
with the complete URL as the first argument works for me:Specifying the
method
and theurl
separately also works:You might want to check that your server is running and that you're not behind a proxy or firewall that prevents access on that port.
I realize the question asks for the request module but in a more general context, if using the http module, you can use the
port
key docs.e.g.