Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 344
Andrew M Avatar asked Oct 14 '11 19:10

Andrew M


People also ask

How do I read a text file from a URL in node JS?

Or if you don't need to save to a file first, and you just need to read the CSV into memory, you can do the following: var request = require('request'); request. get('http://www.whatever.com/my.csv', function (error, response, body) { if (!

How do you get variables in Express js in the GET method?

In Express. js, you can directly use the req. query() method to access the string variables. As per the documentation, the req.

What is Express () in node JS?

Express is a node js web application framework that provides broad features for building web and mobile applications. It is used to build a single page, multipage, and hybrid web application. It's a layer built on the top of the Node js that helps manage servers and routes.


1 Answers

var options = {
  host: 'www.google.com',
  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);
});

http://nodejs.org/docs/v0.4.11/api/http.html#http.get

like image 131
chovy Avatar answered Oct 20 '22 14:10

chovy