"TypeError: не удается прочитать свойство "apply" неопределенного"

использование node, express, socket.Ио, Джейд и угловой. Получение ошибки:TypeError: Cannot read property 'apply' of undefined. Есть предложения?

.js:
module.exports = function(app, res) {
  res.render('index', { title: 'Express' });
  var io = app.get('io');
  io.on('connection', function(socket){
  });
};
.Джейд:
extends layout

block content

script.
    var app = angular.module('hackigur', []);
    var socket = io.connect();
    var refreshTimer = 10;

    app.controller('UpdateController', function($scope){
        //socket.on('update', function(msg){
            //$scope.refreshTimer = msg;
            //$scope.$apply();
        //});

        setInterval(secondTick,1000);

        function secondTick() {
            if(refreshTimer != 0) {
                refreshTimer -= 1;
            }
            $scope.refreshTimer = refreshTimer;
            $scope.$apply();
        };
    });

h1= title
p Welcome to #{title}

div(ng-controller="UpdateController")
    p(ng-bind="refreshTimer")

макет.Джейд:

doctype html
html(ng-app="hackigur")
  head
    title= title
    script(src = "/socket.io/socket.io.js")
    script(src = "/js/angular/angular.min.js")
  body
    block content

полный текст сообщения об ошибке:

Server listening on port 3000
TypeError: Cannot read property 'apply' of undefined
    at Server.(anonymous function) [as on] (D:Projectshackigurnode_modulesso
cket.iolibindex.js:364:15)
    at module.exports (D:Projectshackigurserverapiindex.js:30:8) at ...

1 ответов


мой router, который назвал меня index.js принят app на module.export такие как:

module.export = function (app) {
    app.get( ... , function(..., res) { 
        require(index.js)(app)(res);
};

мне нужно было объявить переменную для app внешний к моему module.export:

var x;
module.export = function (app) {
    x = app;
        app.get( ... , function(..., res) { 
        require(index.js)(x)(res);
};

не совсем понимаю, почему это сработало, но, похоже, прошло правильно app объект app.get применяя выше.