Node.js:对象不是函数 [英] Node.js: object is not a function

查看:56
本文介绍了Node.js:对象不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用Nodejs并尝试创建我的第一个节点(使用Express)应用程序.我收到错误消息"TypeError:对象不是函数",并显示以下消息:

I have just started working with Nodejs and trying to create my first node (using express)application. I am getting an error "TypeError: object is not a function" with below message:

/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如下:

My server.js is as follows:

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的其他问题,并尝试了一些尝试,但没有帮助.我在这里做错了什么?

I have explored other questions on SO with similar error messages and tried out things but without help. What I am doing wrong here?

推荐答案

我的route.js出现问题,未正确完成.这样做之后,我就能解决问题.

There was an issue with my routes.js which was not completed properly. After doing that I am able to resolve the issue.

这篇关于Node.js:对象不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆