example.js 370 B

123456789101112131415161718192021
  1. var duplexify = require('duplexify')
  2. var http = require('http')
  3. var request = function(opts) {
  4. var req = http.request(opts)
  5. var dup = duplexify()
  6. dup.setWritable(req)
  7. req.on('response', function(res) {
  8. dup.setReadable(res)
  9. })
  10. return dup
  11. }
  12. var req = request({
  13. method: 'GET',
  14. host: 'www.google.com',
  15. port: 80
  16. })
  17. req.end()
  18. req.pipe(process.stdout)