when i use nodemon in vs code terminal i get this error
throw new 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:UserswBkStudioProjectsdevmoblibflutterbackendnode_modulesexpresslibrouterindex.js:469:13)
at Function.<anonymous> (C:UserswBkStudioProjectsdevmoblibflutterbackendnode_modulesexpresslibapplication.js:227:21)
at Array.forEach (<anonymous>)
at Function.use (C:UserswBkStudioProjectsdevmoblibflutterbackendnode_modulesexpresslibapplication.js:224:7)
at Object.<anonymous> (C:UserswBkStudioProjectsdevmoblibflutterbackendindex.js:14:5)
at Module._compile (node:internal/modules/cjs/loader:1358:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
at Module.load (node:internal/modules/cjs/loader:1208:32)
at Module._load (node:internal/modules/cjs/loader:1024:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
Node.js v20.16.0
[nodemon] app crashed – waiting for file changes before starting…
this is my index.js code:
`const express = require('express')
const app = express()
const port = 8080 || process.env.PORT
const cors = require('cors')
const bodyParser = require('body-parser')
const mongoose = require('mongoose')
mongoose.connect("mongodb://localhost:27017/mydb")
app.use(cors())
app.use(bodyParser.urlencoded({extended:true}))
app.use(bodyParser.json())
app.listen(port,()=>{
console.log('port running on '+port)
})`
and this is my router.js code:
const express = require('express')
const User = require('../models/user.model')
const router = express.Router()
router.post('/signin',(req,res)=>{
console.log('hello world')
})
type here
module.exports = router
New contributor
wael wbk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.