Node.js:object不是函数

时间:2015-02-25 07:50:39

标签: node.js express

我刚刚开始使用Nodejs并尝试创建我的第一个节点(使用express)应用程序。我收到错误“TypeError:object is not function”,并显示以下消息:

/home/sears/workspace/Express/server.js:38
require('./app/routes.js')(app,passport);
                      ^
TypeError: object is not a function
at Object.<anonymous> (/home/sears/workspace/Express/server.js:38:27)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:929:3

我的server.js如下:

var express = require('express');
var app = express();
var port = process.env.PORT || 8080;

var mongoose = require('mongoose');
var passport = require('passport');
var flash = require('connect-flash');

var morgan = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');

var configDB = require('./app/config/database.js');
var mysqlDB = require('mysql');

// Config

mongoose.connect(configDB.url);

// require('./config/passport')(passport); // pass passport for configuration

app.use(morgan('dev'));
app.use(cookieParser());
app.use(bodyParser());

app.set('view engine', 'ejs');

app.use(session({
    secret : 'ilovescotchscotchyscotchscotch'
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());

// routes

require('./app/routes.js')(app, passport);

// launch
app.listen(port);
console.log("The magic is happening on port " + port);

我已经在SO上探讨了其他类似错误消息的问题并尝试过但没有帮助。 我在这做错了什么?

1 个答案:

答案 0 :(得分:0)

我的routes.js存在问题但未正确完成。 在这之后我能够解决问题。