表达TypeError:undefined不是函数

时间:2015-07-27 10:54:27

标签: javascript node.js express

我是节点和快递的菜鸟,当我运行我的应用程序时,我有这个错误。有解决方案吗我的错误就在这里" app.use(express.static(user));"但我不确定。

var express = require('express');
var http = require('http');
var path = require('path');

var app = express();

// modulos
var home = require('./controllers/home');
var model = require('./models');
var user = require('./controllers/user');

// all environments
app.set('port', process.env.PORT || 3005);
app.set('views', __dirname + '/layouts');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(user));

// development only
if ('development' == app.get('env')) {
  app.use(express.errorHandler());
}

// rutas
app.use(home);

错误

快车 500 TypeError:undefined不是函数

at Object.posix.isAbsolute (path.js:479:15)
at posix.normalize (path.js:461:26)
at SendStream.root.SendStream.from (/Applications/XAMPP/xamppfiles/htdocs/gestor/angular/jordi/node_modules/express/node_modules/send/lib/send.js:116:16)
at Object.staticMiddleware [as handle] (/Applications/XAMPP/xamppfiles/htdocs/gestor/angular/jordi/node_modules/express/node_modules/connect/lib/middleware/static.js:79:8)
at next (/Applications/XAMPP/xamppfiles/htdocs/gestor/angular/jordi/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at resume (/Applications/XAMPP/xamppfiles/htdocs/gestor/angular/jordi/node_modules/express/node_modules/connect/lib/middleware/static.js:60:7)
at SendStream.error (/Applications/XAMPP/xamppfiles/htdocs/gestor/angular/jordi/node_modules/express/node_modules/connect/lib/middleware/static.js:73:37)
at SendStream.emit (events.js:107:17)
at SendStream.error (/Applications/XAMPP/xamppfiles/htdocs/gestor/angular/jordi/node_modules/express/node_modules/send/lib/send.js:147:51)
at SendStream.onStatError (/Applications/XAMPP/xamppfiles/htdocs/gestor/angular/jordi/node_modules/express/node_modules/send/lib/send.js:248:48)
at /Applications/XAMPP/xamppfiles/htdocs/gestor/angular/jordi/node_modules/express/node_modules/send/lib/send.js:320:26
at FSReqWrap.oncomplete (fs.js:95:15)

控制器/用户/ index.js

// JavaScript Document
var express = require('express');
var app = module.exports = express();

app.set('views', __dirname + '/views');

app.get('/user/new', function(request, response) {

  response.render('new');

});

2 个答案:

答案 0 :(得分:1)

$scope.filters = {
  user:{
    name:"John"
  },
  status:{
    name: ["Approved", "For Review"] 
  }
};

答案 1 :(得分:1)

不需要该行(app.use(express.static(user));)删除它。

您正在controller/user/index.js中定义新应用。

您设置的这些选项不会设置为主应用。更改代码如下。

main server.js

var user = require('./controllers/user')(app);  

controllers / user / index.js

// JavaScript Document
module.exports = function (app){

  app.set('views', __dirname + '/views');

  app.get('/user/new', function(request, response) {

    response.render('new');

  });
}