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?

10/14/2011 7:27:44 PM

Accepted Answer

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);

10/14/2011 9:36:07 PM

The problem that you will front is: some webpage loads its contents using JavaScript. Thus, you needs a package, like After-Load which simulates browser's behavior, then gives you the HTML content of that URL .

var afterLoad = require('after-load');
afterLoad('', function(html){

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow