C:\Users\RAHUL\Desktop\2.0 Developer course\YelpCamp\v1\node_modules\express\lib\application.js:210
throw new TypeError('app.use() requires a middleware function')
^
TypeError: app.use() requires a middleware function
at Function.use (C:\Users\RAHUL\Desktop\2.0 Developer course\YelpCamp\v1\node_modules\express\lib\application.js:210:11)
at Object.<anonymous> (C:\Users\RAHUL\Desktop\2.0 Developer course\YelpCamp\v1\app.js:52:5)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47
Asked
Active
Viewed 418 times
0

Shubham Khatri
- 270,417
- 55
- 406
- 400
1 Answers
1
It would be better to include your original code in the question and not just the error, but:
module.exports = router;
means the export is the router
object itself, which Express will be able to use as middleware if it's a valid router.
However, module.exports = { router };
exports an anonymous object with one key, called router
, which points to your router
object. It's equivalent to module.exports = { router: router };
.
This is an example of the object shorthand notation, see this article from Mozilla.

Mark Ormesher
- 2,289
- 3
- 27
- 35