title: How does app.get() work on the server file?
body: <p>I am trying to understand how app.get() works in calling functions when trying to switch between web pages. </p>
  
  <p>I've created a user-login page that assigns a token to the user and checks it in a function. </p>
  
  <p>I use <code>app.post('/login', login);</code> to call the login function which sends the user object to the server. After creating the token I'm hoping to then render the next page in a function after checking the token. (See code below) </p>
  
  <p>However, I don't really understand how <code>app.get('/', checkToken, getProfilePage)</code> is then called. As I don't think it ever gets called. </p>
  
  <p>I've looked at some websites that explain about HTTP requests but I'm struggling to find out, how it all links together inside app.js.</p>
  
  <p><code>App.js</code>:</p>
  
  <pre><code>app.post('/login', login);
  app.get('/', authorize.checkToken, getProfilePage);
  
  function login(req, res, next) {
   userService.login(req.body, (err, user) =&gt; {
      if (err) {
          res.redirect('error.ejs');
          console.log(error.message);
      }
      console.log(user);
      if (!user) {
        res.status(400).json({ success: false, message: 'Username or 
   password is incorrect' });
      }
      else {
        res.json(user);
      }
      })
  }
  </code></pre>
  
  <p>The next login function assigns the token and is used above as middleware:</p>
  
  <pre><code>function login({ username, password }, callback) {
  grabUsers((err, users) =&gt; {
      let user = users.find(u =&gt; u.username === username &amp;&amp; u.password 
  === password);
      if (user) {
          const token = jwt.sign({ username: username }, config.secret, 
              { expiresIn: '24h'
          }
          );
          const { password, ...userWithoutPassword } = user;
          user = {
              ...userWithoutPassword,
              success: true,
              message: 'Authentication successful!',
              token: token
          }
      };  
      callback(null,user);
      })
  </code></pre>
  
  <p>}</p>
  
  <p>Inside <code>authorize.js</code>:</p>
  
  <pre><code>let jwt = require('jsonwebtoken');
  const config = require('./config.js');
  
  let checkToken = (req, res, next) =&gt; {
      console.log("check token running...");
    let token = req.headers['x-access-token'] || 
   req.headers['authorization']; // Express headers are auto 
   converted to lowercase
    if (token.startsWith('Bearer ')) {
      // Remove Bearer from string
      token = token.slice(7, token.length);
    }
  
   if (token) {
     jwt.verify(token, config.secret, (err, decoded) =&gt; {
     if (err) {
      return res.json({
        success: false,
        message: 'Token is not valid'
      });
    } else {
      req.decoded = decoded;
      next();
    }
     });
    } else {
   return res.json({
    success: false,
    message: 'Auth token is not supplied'
   });
    }
  };
  
  module.exports = {
   checkToken: checkToken }
  </code></pre>
  
  <p><code>getProfilePage</code> function:</p>
  
  <pre><code>module.exports = {
      getProfilePage: (req, res) =&gt; {
          res.render('profile.ejs');
      }
  }
  </code></pre>
  
  <p>So my login form posts to <code>/login</code> and then once it has been verified I would like to check the token and then call <code>getProfilePage</code>. But how do I call the app.get() after the login data has been posted and authenticated?</p>