Created
September 8, 2017 21:06
-
-
Save nate-getch/c3014f6901798a977393f2ef3eedcde0 to your computer and use it in GitHub Desktop.
Node.js script to download Google logo thru external request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
http.createServer(function(req, res) { | |
var externalReq = http.request({ | |
hostname: "www.google.com", | |
path: "/images/srpr/logo11w.png" | |
}, function(externalRes) { | |
res.setHeader("content-disposition", "attachment; filename=logo.png"); | |
externalRes.pipe(res); | |
}); | |
externalReq.end(); | |
}).listen(8080); | |
// using request module | |
var http = require('http'); | |
var request = require('request'); | |
http.createServer(function(req, res) { | |
res.setHeader("content-disposition", "attachment; filename=logo.png"); | |
request('http://google.com/images/srpr/logo11w.png').pipe(res); | |
}).listen(8080); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment