Last active
December 20, 2015 07:49
-
-
Save kenany/6096236 to your computer and use it in GitHub Desktop.
hyperquest + nock = invincible server
This file contains hidden or 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 hyperquest = require('hyperquest'); | |
| var through = require('through'); | |
| var req = hyperquest.get('http://jsonip.com'); | |
| req.pipe(through(write, end)); | |
| var data = ''; | |
| function write(buf) { data += buf; } | |
| function end() { | |
| data = JSON.parse(data); | |
| console.log('Your IP address is ' + data.ip); | |
| } |
This file contains hidden or 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 hyperquest = require('hyperquest'); | |
| var through = require('through'); | |
| var nock = require('nock'); | |
| var scope = nock('http://jsonip.com') | |
| .get('/') | |
| .reply(200, '{"ip": "127.0.0.1"}'); | |
| var req = hyperquest.get('http://jsonip.com'); | |
| req.pipe(through(write, end)); | |
| var data = ''; | |
| function write(buf) { data += buf; } | |
| function end() { | |
| data = JSON.parse(data); | |
| console.log('Your IP address is ' + data.ip); | |
| } | |
| // Your IP address is 127.0.0.1 | |
| // | |
| // http.js:458 | |
| // this.socket.destroy(error); | |
| // ^ | |
| // TypeError: Cannot call method 'destroy' of undefined | |
| // at OverridenClientRequest.OutgoingMessage.destroy (http.js:458:15) | |
| // at Stream.<anonymous> (hyperquest\index.js:49:41) | |
| // at Stream.EventEmitter.emit (events.js:126:20) | |
| // at Stream.stream.destroy (through\index.js:80:12) | |
| // at through\index.js:55:16 | |
| // at process.startup.processNextTick.process._tickCallback (node.js:244:9) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment