Skip to content

Instantly share code, notes, and snippets.

@kenany
Last active December 20, 2015 07:49
Show Gist options
  • Select an option

  • Save kenany/6096236 to your computer and use it in GitHub Desktop.

Select an option

Save kenany/6096236 to your computer and use it in GitHub Desktop.
hyperquest + nock = invincible server
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);
}
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