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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…