首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >节点Js、异步Js、监听器必须是一个函数。

节点Js、异步Js、监听器必须是一个函数。
EN

Stack Overflow用户
提问于 2014-01-23 11:44:02
回答 1查看 5.6K关注 0票数 0

下面是下面代码的输出日志,我不知道它为什么要抛出错误,我认为行尾的数字是line numberchar number,我会在代码中发布一些关键行号。

由于某种原因不起作用 系列完成 events.js:171 抛出TypeError(“侦听器必须是函数”); ^ TypeError:侦听器必须是一个函数 在TypeError () 在NativeConnection.EventEmitter.once (events.js:171:11) 在/home/melman/Documents/Git/angular-test/server.js:39:24 在/home/melman/Documents/Git/angular-test/node_modules/async/lib/async.js:5 48:21 在/home/melman/Documents/Git/angular-test/node_modules/async/lib/async.js:2 24:13 迭代(/home/melman/Documents/Git/angular-test/node_modules/async/lib/a sync.js:131:13) 在(/home/melman/Documents/Git/angular-test/node_modules/as async.eachSeries ync/lib/异步ync:147:9) 在(/home/melman/Documents/Git/angular-test/node_modules/async/lib _asyncMap /async.js:223:9) 在(/home/melman/Documents/Git/angular-test/node_modules/as Object.mapSeries ync/lib/syc.js:213:23) 在(/home/melman/Documents/Git/angular-test/node_modules Object.async.series /异步/lib/syc.js:546:19)

代码语言:javascript
复制
28: var serverConfiguration = {
    init: function (){
30:       var self = this;

        async.series([
            function (callback) {
                // connect to the db
                db.connect('mongodb://localhost/piautomation');

                var dbConn = db.connection;
                dbConn.on('error', console.error.bind(console, 'connection error:'));
                dbConn.once('open', callback(null));
40:         },
            function (callback) {
                console.log('Configure the db');
                self.models = require('./server/config/mongoose')(db); // setup the db with the models and schemas
                callback(null);
            },
            function (callback) {
                console.log("Start creating models");
                self.newsApi = require('./server/api/news')(self.models.News); // pass the news api the News model
                callback(null);
50:         },
            function (callback) {
                console.log("configure routes");
                require('./server/config/routes')(app, self.newsApi, clientDir, callback); // set up the routes with the model api's functions
            },
            function (callback) {
                console.log("http server created");
                var server = http.createServer(app);
                console.log("starting reload");
                reload(server, app);
60:             console.log("start server listen");
                // if we have successful db connection, allow the rest of the app to start up
                server.listen(app.get('port'), function(){
                    console.log("Web server listening in %s on port %d", colors.red(process.env.NODE_ENV), app.get('port'));
                    callback(null);
                });
                console.log("for some reason not working");
                callback(null);
            }
        ], function () {
70:         console.log("series complete");
        });
    }
}.init();
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-23 11:46:15

尝试将第39行从

代码语言:javascript
复制
dbConn.once('open', callback(null));

代码语言:javascript
复制
dbConn.once('open', callback);
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21307186

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档