Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
108
rated 0 times [  113] [ 5]  / answers: 1 / hits: 63354  / 13 Years ago, wed, april 27, 2011, 12:00:00

Inside the code, I want to download http://www.google.com and store it in a string.
I know how to do that in urllib in python. But how do you do it in Node.JS + Express?


More From » http

 Answers
31

Using node.js you can just use the http.request method



http://nodejs.org/docs/v0.4.7/api/all.html#http.request



This method is built into node you just need to require http.



If you just want to do a GET, then you can use http.get



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



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


(Example from node.js docs)



You could also use mikeal's request module



https://github.com/mikeal/request


[#92538] Tuesday, April 26, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kylanalis

Total Points: 438
Total Questions: 85
Total Answers: 102

Location: Barbados
Member since Sun, Nov 27, 2022
1 Year ago
kylanalis questions
Sat, Oct 2, 21, 00:00, 3 Years ago
Tue, Oct 13, 20, 00:00, 4 Years ago
Thu, Feb 13, 20, 00:00, 4 Years ago
Tue, Jan 7, 20, 00:00, 4 Years ago
;