Router.use() requires middleware function but got a Object

4,347 views
Skip to first unread message

Zach Sosana

unread,
Nov 29, 2014, 2:59:59 AM11/29/14
to expre...@googlegroups.com
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









greelgorke

unread,
Dec 1, 2014, 5:57:55 AM12/1/14
to expre...@googlegroups.com
your braces are wrong
app
.use('/', express.static('./static', {maxAge: 60*60*24*1000}));

Zach Sosana

unread,
Dec 1, 2014, 5:20:03 PM12/1/14
to expre...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages