I am trying to put my routes into multiple files to organize based on module. if i only use one file like this all works fine
const apiRoutes = require('./routes/api')
app.use('/api', apiRoutes);
but when i use the below code in my index.js and register 2 files
const apiRoutes = require('./routes/api')
const apiRoutes2 = require('./routes/leads')
app.use(express.json());
app.use('/api', apiRoutes);
app.use('/leads', apiRoutes2);
i get this error
C:\nodeRoot\node_modules\express\lib\router\index.js:458
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:\nodeRoot\node_modules\express\lib\router\index.js:458:13)
at Function.<anonymous> (C:\nodeRoot\node_modules\express\lib\application.js:220:21)
at Array.forEach (<anonymous>)
So not sure if you can only register 1 file for routes or what else is causing this issue