I have a node/express crud api. In the beginning it was working properly bu then I can't access it on both my localhost and postman api. And when I try to test it in my postman it returns "socket hang up error". After that I debugged it on my terminal and this came:
Debugger attached.
Waiting for the debugger to disconnect...
/Users/air/Desktop/Node_Docker/node_modules/express/lib/router/route.js:211
throw new Error(msg);
^
Error: Route.post() requires a callback function but got a [object Object]
at Route.<computed> [as post] (/Users/air/Desktop/Node_Docker/node_modules/express/lib/router/route.js:211:15)
at Object.<anonymous> (/Users/air/Desktop/Node_Docker/routes/postRoutes.js:11:4)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/air/Desktop/Node_Docker/index.js:23:20)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
Waiting for the debugger to disconnect...
And this is my router.js file:
const express = require("express");
const postController = require("../controllers/postController");
const protect = require("../middleware/authMiddleware");
const router = express.Router()
router.route("/").get(postController.getAllPosts).post(protect, postController.createPost);
router.route("/:id").get(postController.getOnePost).patch(postController.updatePost).delete(postController.deletePost);
module.exports = router;
How can I fix that?