javascript - Node Js、Async Js、Listener 必须是函数

标签 javascript node.js angularjs

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

for some reason not working
series complete

events.js:171
throw TypeError('listener must be a function');
^ TypeError: listener must be a function
at TypeError ()
at NativeConnection.EventEmitter.once (events.js:171:11)
at /home/melman/Documents/Git/angular-test/server.js:39:24
at /home/melman/Documents/Git/angular-test/node_modules/async/lib/async.js:5 48:21
at /home/melman/Documents/Git/angular-test/node_modules/async/lib/async.js:2 24:13
at iterate (/home/melman/Documents/Git/angular-test/node_modules/async/lib/a
sync.js:131:13)
at async.eachSeries (/home/melman/Documents/Git/angular-test/node_modules/as
ync/lib/async.js:147:9)
at _asyncMap (/home/melman/Documents/Git/angular-test/node_modules/async/lib
/async.js:223:9)
at Object.mapSeries (/home/melman/Documents/Git/angular-test/node_modules/as
ync/lib/async.js:213:23)
at Object.async.series (/home/melman/Documents/Git/angular-test/node_modules
/async/lib/async.js:546:19)

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();

最佳答案

尝试更改第 39 行

dbConn.once('open', callback(null));

dbConn.once('open', callback);

关于javascript - Node Js、Async Js、Listener 必须是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21307186/

相关文章:

javascript - 如何使用正则表达式在 angularjs 上打印值?

javascript - 如何从 javascript 创建 jQuery Mobile 按钮?

javascript - 如何在 OpenCV.js 中获取轮廓 Angular 点的坐标?

JavaScript for 循环混淆

node.js - 使用返回 promise 的多个步骤对自定义查找器进行 Sequelize

node.js - 使用 Node 请求管道图像,但在非 200 http 状态代码时中止

javascript - Angular ,项目详细信息

javascript - 防止多个网络通知?

node.js - 不带 ssl 的 npm 安装

javascript - Strtr 用于 angularjs,就像 PHP 中一样(尝试音译)