2014년 12월 3일 수요일

[Express-js] Router.use() requires middleware function but got a Object

Can't seem to figure out this error...

this is a simple static express app...

var express = require('express');
var app = express();

app
.use('/', express.static('./static'), {maxAge: 60*60*24*1000});

app
.use('/images', express.static('../images'));

app
.get('/', function(req, res) {
  res
.redirect('/static.html');
});

app
.listen(3000);

This is the error
/workspace/node_modules/express/lib/router/index.js:438
throw new TypeError('Router.use() requires middleware function but got a ^
TypeError: Router.use() requires middleware function but got a Object



your braces are wrong
app
.use('/', express.static('./static', {maxAge: 60*60*24*1000}));




Thanks for your help

I was using v4.1* and got this error. I simply uninstalled it and reinstalled with v4.0.* and all works fine.


댓글 없음:

댓글 쓰기