title: How to pass middleware to specified routes in express node.js
body: <p>I have a middleware (gateMan) that checks if user is logged in, i don't want the middleware (gateMan) to fire on all routes. However, it would be fired on 98% of my routes, how can i achieve this without calling the middleware on each of the route.</p>
  
  <p><strong>Middleware</strong></p>
  
  <pre><code>const gateMan = (req,res,next)=&gt;{
      if(req.user)
          next();
      else{
          res.redirect('/auth/login');
          res.end();
      }
  };
  </code></pre>
  
  <p><strong>Route sample</strong></p>
  
  <pre><code>app.use('/',staticRoute);
  app.use('/auth',authRoute);
  app.use('/user',gateMan,userRoute);
  app.use('/mocks',gateMan,mockRoute);
  app.use('/sample2',sample2Route);
  app.use('/sample3',sample3Route);
  app.use('/sample4',sample4Route);
  </code></pre>
  
  <p>I want to apply <strong>gateMan</strong> to all routes except <strong>staticRoute</strong> and <strong>authRoute</strong>. I'm thinking if there is a way i can just pass all routes into and array and apply the middleware to them, how possible is this ?</p>