{"action":"created","issue":{"url":"https://api.github.com/repos/emiloberg/node-red-contrib-file-function/issues/1","labels_url":"https://api.github.com/repos/emiloberg/node-red-contrib-file-function/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/emiloberg/node-red-contrib-file-function/issues/1/comments","events_url":"https://api.github.com/repos/emiloberg/node-red-contrib-file-function/issues/1/events","html_url":"https://github.com/emiloberg/node-red-contrib-file-function/issues/1","id":121928138,"number":1,"title":"node object is undefined","user":{"login":"masalinas","id":1216181,"avatar_url":"https://avatars.githubusercontent.com/u/1216181?v=3","gravatar_id":"","url":"https://api.github.com/users/masalinas","html_url":"https://github.com/masalinas","followers_url":"https://api.github.com/users/masalinas/followers","following_url":"https://api.github.com/users/masalinas/following{/other_user}","gists_url":"https://api.github.com/users/masalinas/gists{/gist_id}","starred_url":"https://api.github.com/users/masalinas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/masalinas/subscriptions","organizations_url":"https://api.github.com/users/masalinas/orgs","repos_url":"https://api.github.com/users/masalinas/repos","events_url":"https://api.github.com/users/masalinas/events{/privacy}","received_events_url":"https://api.github.com/users/masalinas/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-13T16:21:53Z","updated_at":"2015-12-13T16:48:43Z","closed_at":null,"body":"In the javascript used with your node I have a asyncronous called, so I must use the node object to call the next node, i obtain a error because the node object is undefined always. \r\n\r\nThis is my code:\r\n\r\n... \r\nDevice.find( { where: { deviceHubId: '566d85a22b937b4350d88d19' }, include: 'deviceType' }, function(err, devices) {\r\n    if (err) return err;\r\n\r\n    msg.payload = devices;\r\n    node.send(msg);\r\n});\r\n\r\nreturn;\r\n\r\n\r\nThe same code is tested without your node and the result is ok, but if use your node with the same code the node object is undefined and crash.\r\n\r\nRegards."},"comment":{"url":"https://api.github.com/repos/emiloberg/node-red-contrib-file-function/issues/comments/164276758","html_url":"https://github.com/emiloberg/node-red-contrib-file-function/issues/1#issuecomment-164276758","issue_url":"https://api.github.com/repos/emiloberg/node-red-contrib-file-function/issues/1","id":164276758,"user":{"login":"masalinas","id":1216181,"avatar_url":"https://avatars.githubusercontent.com/u/1216181?v=3","gravatar_id":"","url":"https://api.github.com/users/masalinas","html_url":"https://github.com/masalinas","followers_url":"https://api.github.com/users/masalinas/followers","following_url":"https://api.github.com/users/masalinas/following{/other_user}","gists_url":"https://api.github.com/users/masalinas/gists{/gist_id}","starred_url":"https://api.github.com/users/masalinas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/masalinas/subscriptions","organizations_url":"https://api.github.com/users/masalinas/orgs","repos_url":"https://api.github.com/users/masalinas/repos","events_url":"https://api.github.com/users/masalinas/events{/privacy}","received_events_url":"https://api.github.com/users/masalinas/received_events","type":"User","site_admin":false},"created_at":"2015-12-13T16:48:43Z","updated_at":"2015-12-13T16:48:43Z","body":"I resolve the problem patching your code like this:\r\n\r\nfunction sendResults(node,_msgid,msgs) {\r\n        if (msgs == null) {\r\n            return;\r\n        } else if (!util.isArray(msgs)) {\r\n            msgs = [msgs];\r\n        }\r\n        var msgCount = 0;\r\n        for (var m=0;m<msgs.length;m++) {\r\n            if (msgs[m]) {\r\n                if (util.isArray(msgs[m])) {\r\n                    for (var n=0; n < msgs[m].length; n++) {\r\n                        msgs[m][n]._msgid = _msgid;\r\n                        msgCount++;\r\n                    }\r\n                } else {\r\n                    msgs[m]._msgid = _msgid;\r\n                    msgCount++;\r\n                }\r\n            }\r\n        }\r\n        if (msgCount>0) {\r\n            node.send(msgs);\r\n        }\r\n    }\r\n\r\nvar sandbox = {\r\n\t\t\tconsole:console,\r\n\t\t\tutil:util,\r\n\t\t\tBuffer:Buffer,\r\n                        node: node,\r\n            __node__: {\r\n                log: function() {\r\n                    node.log.apply(node, arguments);\r\n                },\r\n                error: function() {\r\n                    node.error.apply(node, arguments);\r\n                },\r\n                warn: function() {\r\n                    node.warn.apply(node, arguments);\r\n                },\r\n                send: function(id, msgs) {\r\n                    sendResults(node, id, msgs);\r\n                },\r\n                on: function() {\r\n                    node.on.apply(node, arguments);\r\n                },\r\n                status: function() {\r\n                    node.status.apply(node, arguments);\r\n                }\r\n            },\r\n\t\t\tcontext: {\r\n\t\t\t\tglobal:RED.settings.functionGlobalContext || {}\r\n\t\t\t}\r\n\t\t};\r\n\r\nWhat is your opinion"}}