title: Get user id from jsonwebtoken in node with passport
body: <p>I use <code>passport jwt</code> strategy and here is my code snippet:</p>
  <pre><code>'use strict';
  
  const config = require('../config');
  const User = require('../models/user.model');
  const passportJWT = require('passport-jwt');
  
  const ExtractJwt = passportJWT.ExtractJwt;
  const JwtStrategy = passportJWT.Strategy;
  
  const jwtOptions = {
      secretOrKey: config.secret,
      jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken()
  };
  
  const jwtStrategy = new JwtStrategy(jwtOptions, (jwtPayload, done) =&gt; {
      console.log(jwtPayload);
      User.findById(jwtPayload.sub, (err, user) =&gt; {
          if (err) return done(err, null);
          if (user) {
              return done(null, user)
          } else {
              return done(null, false)
          }
      })
  });
  
  exports.jwtOptions = jwtOptions;
  exports.jwt = jwtStrategy;
  </code></pre>
  <p>here I'm setting the strategy and everything works correctly. Now I want to create endpoint to add article with UserId retrieved from the token (article has userId String in its schema).</p>
  <p>How am I suppose to get userId from the token?</p>
  <p>In <code>new JwtStrategy</code> it's already happening because I have payload which allow me to <code>findById</code> and therefore authenticate the call but should I somehow reuse this file or create new named for example getUserId?</p>