aswi2020vldc-gitlab/templetes/node_modules/duplexify/example.js @ 78a2184f
1 |
var duplexify = require('duplexify') |
---|---|
2 |
var http = require('http') |
3 |
|
4 |
var request = function(opts) { |
5 |
var req = http.request(opts) |
6 |
var dup = duplexify() |
7 |
dup.setWritable(req) |
8 |
req.on('response', function(res) { |
9 |
dup.setReadable(res) |
10 |
})
|
11 |
return dup |
12 |
}
|
13 |
|
14 |
var req = request({ |
15 |
method: 'GET', |
16 |
host: 'www.google.com', |
17 |
port: 80 |
18 |
})
|
19 |
|
20 |
req.end() |
21 |
req.pipe(process.stdout) |