1
votes

I have index.js file like this and

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

//Import Routes
const authRoute = require('./routes/auth');

//Route Middlewares
app.use('/api/user', authRoute);

app.listen(3000, () => console.log('Server Up and running'));

auth.js like this one

const router = require('express').Router();

router.post('/register', (req, res) => {
    res.send('Register');
})
module.exports = router;

Why i get the TypeError('Router.use() requires a middleware function but got a ' + gettype(fn)) ^

TypeError: Router.use() requires a middleware function but got a Object at Function.use (C:\Users\xxx\Desktop\Websites\Authentication\node_modules\express\lib\router\index.js:458:13) at Function. (C:\Users\xxx\Desktop\Websites\Authentication\node_modules\express\lib\application.js:220:21)

1
sometimes i got this error when i was rewriting the route handler. i just restartet the application and it worked again - Ifaruki
Restarting doesn't help - roman

1 Answers

0
votes

You may try to re-write your auth.js in the following format, I think that will solve the issue:

router.route('/register').post((req, res) => {  .............