I have one question regarding Node js
Method 1:
app.post('/password-reset', resetPassword)
function resetPassword() {
// code here
}
vs
Method 2:
app.post('/password-reset', function(req, res){
// code here
});
I understand that both are doing the same thing but why do we need method 1?
Is that any scenario that I must use method 1?
The only practical difference is that method 1 leaves a resetPassword function in the scope of the module which can be reused later. That isn't likely to be useful for the endpoint function of a route which is likely to be assigned exactly once. You might want to export that function and unit test it though.
Everything else is code style preference. People would probably disagree on which is easier to read / maintain. Pick a style that suits you and the people you work with.