Amazing Aaron Amazing Aaron - 1 year ago 71
Node.js Question

Not even returning an error? node.js request

I have a script that GETS with http.request a website.
I have placed console.log()'s everywhere, yet can't even get it to log.
Here's my code:

var dg = {
hostname: '',
path: '/studio/plugins/info?assetId=12313013',
headers: {
'Accept-Encoding': 'gzip'

var omagawsh = http.request(dg, function(rspn) {
var strn = []
var gunzip = zlib.createGunzip();
gunzip.on('error', function(e) {

gunzip.on('data', function(chunk) {
gunzip.on('end', function() {
omagawsh.on('error', function(e) {


I am using

var zlib = require('zlib')

var http = require('http')

at the top.

Any help is much appreciated, thanks

Answer Source

You never actually write the request which you would do with omgawsh.end(). The request will not actually be sent until this is done.

var omagawsh = http.request(dg, function(rspn) {
    /* snip */  

Since the request is not done, the response callback is not reached. Your calls to omgawsh should be outside the callback.

var omagawsh = http.request(dg, cb);
omagawsh.on("error", handleError)

See the documentation for http.request:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download