Update
The accepted answer was good for last year but today I would use the package everyone else uses: https://github.com/mikeal/request
Original
I'm trying to grab google's logo and save it to my server with node.js.
This is what I have right now and doesn't work:
var options = {
host: 'google.com',
port: 80,
path: '/images/logos/ps_logo2.png'
};
var request = http.get(options);
request.on('response', function (res) {
res.on('data', function (chunk) {
fs.writeFile(dir+'image.png', chunk, function (err) {
if (err) throw err;
console.log('It\'s saved!');
});
});
});
How can I get this working?