javascript - express TypeError: undefined is not a function -
i'm noob node , express , when run app have error. solutions? thing error here "app.use(express.static(user));" don't sure.
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'); // 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 if ('development' == app.get('env')) { app.use(express.errorhandler()); } // rutas app.use(home);
error
express 500 typeerror: undefined not function
at object.posix.isabsolute (path.js:479:15) @ posix.normalize (path.js:461:26) @ sendstream.root.sendstream.from (/applications/xampp/xamppfiles/htdocs/gestor/angular/jordi/node_modules/express/node_modules/send/lib/send.js:116:16) @ object.staticmiddleware [as handle] (/applications/xampp/xamppfiles/htdocs/gestor/angular/jordi/node_modules/express/node_modules/connect/lib/middleware/static.js:79:8) @ next (/applications/xampp/xamppfiles/htdocs/gestor/angular/jordi/node_modules/express/node_modules/connect/lib/proto.js:190:15) @ resume (/applications/xampp/xamppfiles/htdocs/gestor/angular/jordi/node_modules/express/node_modules/connect/lib/middleware/static.js:60:7) @ sendstream.error (/applications/xampp/xamppfiles/htdocs/gestor/angular/jordi/node_modules/express/node_modules/connect/lib/middleware/static.js:73:37) @ sendstream.emit (events.js:107:17) @ sendstream.error (/applications/xampp/xamppfiles/htdocs/gestor/angular/jordi/node_modules/express/node_modules/send/lib/send.js:147:51) @ sendstream.onstaterror (/applications/xampp/xamppfiles/htdocs/gestor/angular/jordi/node_modules/express/node_modules/send/lib/send.js:248:48) @ /applications/xampp/xamppfiles/htdocs/gestor/angular/jordi/node_modules/express/node_modules/send/lib/send.js:320:26 @ fsreqwrap.oncomplete (fs.js:95:15)
controllers/user/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'); });
no need of line(app.use(express.static(user));
) remove that.
you defining new app in controller/user/index.js
.
those options have set not set main app. change code below.
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'); }); }
Comments
Post a Comment