アップデート
受け入れられた回答は昨年は良かったのですが、今日は他のみんなが使用しているパッケージを使用します: https ://github.com/mikeal/request
オリジナル
Googleのロゴを取得して、node.jsを使用してサーバーに保存しようとしています。
これは私が今持っているものであり、機能しません:
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!');
});
});
});
どうすればこれを機能させることができますか?