/home/cloudcoke/my/playground/router/node_modules/express/lib/router/index.js:469
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 (/home/cloudcoke/my/playground/router/node_modules/express/lib/router/index.js:469:13)
at Object.<anonymous> (/home/cloudcoke/my/playground/router/routes/index.js:5:8)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
at Module._load (node:internal/modules/cjs/loader:878:12)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (/home/cloudcoke/my/playground/router/server.js:3:16)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
Node.js v18.12.1
Router.use()
에서 미들웨어가 필요한데 그걸 전달해주지 않아서 생기는 에러였다.module.exports
를 해주지 않아서 생기는 에러였다.const express = require("express");
const router = express.Router();
const board = require("./board.route");
router.use("/board", board);
module.exports = router;
routes/board.route.js
const express = require("express");
const router = express.Router();
router.get("/list", (req, res) => {
res.send("list page");
});
module.exports
를 해주니 오류가 해결됬다.const express = require("express");
const router = express.Router();
const board = require("./board.route");
router.use("/board", board);
module.exports = router;
routes/board.route.js
const express = require("express");
const router = express.Router();
router.get("/list", (req, res) => {
res.send("list page");
});
module.exports = router;