'What does this error mean and how would I fix it: throw new TypeError('app.use() requires a middleware function')?

I am trying to create a login page and sign up page, my app.js gives me this error, I think it is the last line of this code. I can send you the other components(files) for this express app. I cannot understand what is causing this error.

const express = require('express');
const mongoose = require('mongoose');
// Routes
const authRoutes = require('./routes/authRoutes');

const app = express();

// middleware
app.use(express.static('public'));

app.use((err, req, res, next) => {
  res.locals.error = err;
  res.status(err.status);
  res.render('error');
});

// view engine
app.set('view engine', 'ejs');

// database connection
const dbURI = '<database, username and password>';
mongoose.connect(dbURI, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex:true })
  .then((result) => app.listen(3000))
  .catch((err) => console.log(err));

// routes
app.get('/', (req, res) => res.render('home'));
app.get('/smoothies', (req, res) => res.render('smoothies'));
app.use(authRoutes);

authRoutes.js

const { Router } = require('express')
const authController = require('./authController.js')
 
const router = Router();

router.get('/signup', authController.signup_get);
router.get('/signup', authController.signup_post);
router.get('/login', authController.login_get);
router.get('/login', authController.login_post);

module.export = router;

authController.js

module.exports.signup_get = (req, res) => {
  res.render('signup');  
}

module.exports.login_get = (req, res) => {
    res.render('login');  
}

module.exports.signup_post = (req, res) => {
    res.send('signup');  
}

module.exports.login_post = (req, res) => {
    res.send('login');  
}


Solution 1:[1]

You are exporting incorrectly in authRoutes.js.

Change this:

module.export = router;

to this:

module.exports = router;

FYI, a little debugging on your own by simply doing a console.log(authRoutes) should have been able to show you where to look for the problem. If you get an error when you attempt to use authRoutes, you look at what it is and where it came from to see why it's not working. This is basic debugging and there is an expectation that you've done basic debugging before you post your question here.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jfriend00