Writing custom middleware functions in NodeJS