Andrew M Andrew M - 1 year ago 132
Node.js Question

Get URL Contents in Node.js with Express

How would I go about downloading the contents of a URL in Node when using the Express framework? Basically, I need to complete the Facebook authentication flow, but I can't do this without GETing their OAuth Token URL.

Normally, in PHP, I'd use Curl, but what is the Node equivalent?

Answer Source
var options = {
  host: '',
  port: 80,
  path: '/index.html'

http.get(options, function(res) {
  console.log("Got response: " + res.statusCode);
}).on('error', function(e) {
  console.log("Got error: " + e.message);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download