I've created a NodeJS Express app. But my express route is invocking multiple routes function, one after another, but I only need one at a time.
My express app.js
app.use(routes)
Express router:
const router = express.Router();
router.post("/product", controller.productFunction)
router.post("/user", controller.userFunction)
router.get("/:id", idController.getId)
Whenever I create a post request for "/product"
route, first the productFunction
is invocked, but then the "/:id"
routes getId
function is also get invocked. Same thing happen for /user
route as well. Always /:id
route is getting invocked.
Is there any way to prevent this?
I even tried this way, but after the homepage loading then again it invockes getId
function.
app.get("/", (req, res, next) => {
res.sendFile(..........);
});
app.use(routes);