node.js and node-rest-client TypeError: Cannot read property 'tunnel' of undefined

799 views
Skip to first unread message

Josh Longbrake

unread,
Feb 27, 2014, 10:43:39 AM2/27/14
to nod...@googlegroups.com

I am getting the error listed in the title when using the code posted below. This is based off of: https://www.npmjs.org/package/node-rest-client

fyi: the Bearer, path and client url have been masked as they are client sensitive items.

middleware:

angular.module('ruleService', [])

    .factory('Rules', function($http) {
        return {

            provision : function(data) {
                console.log('provision: ' + data)
                return $http.put('/api/provisions/', data);
            }
}

service:

module.exports = function (app) {
    var Client = require('node-rest-client').Client;
    console.log('mdmController:');

    app.put('/api/provisions/', function (data) {

        console.log("provisions prov:" + JSON.stringify(data.body.prov))
        console.log("provisions id:" + JSON.stringify(data.body.id))

        var client = new Client();

        var args = {
            path: '/api/path/to/url/'+ data.body.id,
            port: 443,
            headers: {'Authorization': 'Bearer 0c92f5177d5e818fcc680681f1e9b6895bd5491153'},
            data: data.body.prov
        };

        console.log('args:' + args)

        client.put("https://notTheActualSite.com", args, function (data, response) {
            console.log('put data:' + data);
            console.log('put response:' + response);
        });

    });
}


What is being handled incorrectly? As always any and all assistance is greatly appreciated, so Thanks in advance!

// ravi

unread,
Feb 27, 2014, 12:01:43 PM2/27/14
to nod...@googlegroups.com
On Feb 27, 2014, at 10:43 AM, Josh Longbrake <jo...@studiobrainchild.com> wrote:
>
> I am getting the error listed in the title when using the code posted below. This is based off of: https://www.npmjs.org/package/node-rest-client
>

Can you send us the full stack trace?

—ravi
> --
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
> ---
> You received this message because you are subscribed to the Google Groups "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Josh Longbrake

unread,
Feb 27, 2014, 1:19:46 PM2/27/14
to nod...@googlegroups.com
Sure here it is:

TypeError: Cannot read property 'tunnel' of undefined
    at new exports.Client (/Users/jlongbrake/Desktop/sitename/node_modules/node-rest-client/lib/node-rest-client.js:14:42)
    at /Users/jlongbrake/Desktop/sitename/controller/mdmController.js:10:22
    at callbacks (/Users/jlongbrake/Desktop/sitename/node_modules/express/lib/router/index.js:164:37)
    at param (/Users/jlongbrake/Desktop/sitename/node_modules/express/lib/router/index.js:138:11)
    at pass (/Users/jlongbrake/Desktop/sitename/node_modules/express/lib/router/index.js:145:5)
    at Router._dispatch (/Users/jlongbrake/Desktop/sitename/node_modules/express/lib/router/index.js:173:5)
    at Object.router (/Users/jlongbrake/Desktop/sitename/node_modules/express/lib/router/index.js:33:10)
    at next (/Users/jlongbrake/Desktop/sitename/node_modules/express/node_modules/connect/lib/proto.js:193:15)
    at Object.allowCrossDomain [as handle] (/Users/jlongbrake/Desktop/sitename/server.js:21:9)
    at next (/Users/jlongbrake/Desktop/sitename/node_modules/express/node_modules/connect/lib/proto.js:193:15)


sitename is not the actual app name (to protect the innocent...)

Thanks for getting eyes on it!  Its baffeling to me that Im having such difficulty in making a single PUT request...
my goal here:

https.request({
host: 'sitename.com',
port: 443,
data: {'restrictions':data.body.prov},
path: '/api/3/' + data.body.id,
method: 'PUT',
headers: {'Authorization': 'Bearer 0c92f5177d5e818fcc680681f1e9b6895bd5491153'}})

Josh Longbrake

unread,
Feb 27, 2014, 3:11:11 PM2/27/14
to nod...@googlegroups.com
at /Users/jlongbrake/Desktop/sitename/controller/mdmController.js:10:22 would be this line from the code above:   var client = new Client();

// ravi

unread,
Feb 27, 2014, 4:34:41 PM2/27/14
to nod...@googlegroups.com
On Feb 27, 2014, at 1:19 PM, Josh Longbrake <jo...@studiobrainchild.com> wrote:
Sure here it is:

TypeError: Cannot read property 'tunnel' of undefined
    at new exports.Client (/Users/jlongbrake/Desktop/sitename/node_modules/node-rest-client/lib/node-rest-client.js:14:42)
    at /Users/jlongbrake/Desktop/sitename/controller/mdmController.js:10:22
    at callbacks (/Users/jlongbrake/Desktop/sitename/node_modules/express/lib/router/index.js:164:37)
    at param (/Users/jlongbrake/Desktop/sitename/node_modules/express/lib/router/index.js:138:11)
    at pass (/Users/jlongbrake/Desktop/sitename/node_modules/express/lib/router/index.js:145:5)
    at Router._dispatch (/Users/jlongbrake/Desktop/sitename/node_modules/express/lib/router/index.js:173:5)
    at Object.router (/Users/jlongbrake/Desktop/sitename/node_modules/express/lib/router/index.js:33:10)
    at next (/Users/jlongbrake/Desktop/sitename/node_modules/express/node_modules/connect/lib/proto.js:193:15)
    at Object.allowCrossDomain [as handle] (/Users/jlongbrake/Desktop/sitename/server.js:21:9)
    at next (/Users/jlongbrake/Desktop/sitename/node_modules/express/node_modules/connect/lib/proto.js:193:15)


The trouble is with the module. I notice the offending line of code is different in the NPM installed module in comparison to the correct/bug-free version on GitHub.

The buggy line in the NPM installed node module:

    self.useProxyTunnel = self.options.proxy.tunnel===undefined?true:self.options.proxy.tunnel,


    self.useProxyTunnel = (!self.useProxy || self.options.proxy.tunnel===undefined)?false:self.options.proxy.tunnel,

—ravi


Josh Longbrake

unread,
Feb 27, 2014, 4:57:21 PM2/27/14
to nod...@googlegroups.com

Hmm.  Its the installed package from homebrew but it may be an older version of homebrew / NPM.  Good catch, ill update and try again.  From your view does anything else look inherently wrong?

Thanks for the fresh eyes!

--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
You received this message because you are subscribed to a topic in the Google Groups "nodejs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs/g4ch8Z9c4cg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nodejs+un...@googlegroups.com.

// ravi

unread,
Feb 27, 2014, 5:07:22 PM2/27/14
to nod...@googlegroups.com
On Feb 27, 2014, at 4:57 PM, Josh Longbrake <jo...@studiobrainchild.com> wrote:

Hmm.  Its the installed package from homebrew but it may be an older version of homebrew / NPM. 


Josh, it’s not Homebrew or NPM themselves, but the version of node-rest-client that’s in the NPM repository (assuming you installed the module using ’nom install node-rest-client’ or equivalent). The node-rest-client (in the NPM repository) has the bug that you hit. The code on GitHub does not. Here’s the relevant bug report:


Here’s the fix commit:


You can contact the author to see when he plans to publish it to NPM. In the meantime, if you are in a hurry, you could (factoring risks) copy the fixed file from GitHub.

Good catch, ill update and try again.  From your view does anything else look inherently wrong?


Not related to the issue you report, no.

Thanks for the fresh eyes!


Glad to help,

—ravi



Josh Longbrake

unread,
Feb 28, 2014, 4:21:51 PM2/28/14
to nod...@googlegroups.com
Just wanted to confirm that the github fixed version is working.
Reply all
Reply to author
Forward
0 new messages