Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Express Basics Serving Static Files in Express Adding Static Assets to the App

Vlad Tanasie
Vlad Tanasie
7,201 Points

What might be the cause of this? TypeError: app.use() requires middleware functions

I tried to copy the style files in my project files then I started to get this error after I deleted them I still get it, what might be the cause of this?

Dane Parchment
Dane Parchment
Treehouse Moderator 11,077 Points

Can you provide your code? It would be much easier to help you out if I could see your code.

1 Answer

Dane Parchment
MOD
Dane Parchment
Treehouse Moderator 11,077 Points

I have seen this error before, but without your code I can't be certain, that it's the issue.

Anywhere in your code do you have a line like this: app.use(); without parameters? If so, app.use() actually requires multiple parameters and a callback, it should be formatted as so:

// This is what it should look like
app.use(function (req, res, next) {
  console.log('Time: %d', Date.now());
  next();
});

//Note you don't have to use 'next'
app.use(function (req, res) {
  console.log('Time: %d', Date.now());
});

also note that you don't need to explicitly use req or res but you need to add them as parameters.