Hey I was learning Node as part of course where they made some variable equal to a function
Something like this
const authCheck = (req, res, next) => {
if (req.user) {
next()
} else {
res.redirect("http://localhost:3000/")
}
}
and then they called it in a middleware
router.post("/", authCheck, (req, res) => {
Now, I have usually seen people calling a function like this authCheck()
While that works, I wanted to comprehend the difference between both of them
authCheck()would call the function, (with no arguments, by the way) ...authCheckpasses the function as an argument torouter.postin your example - and something inrouter.postmay callauthCheckif required