title: getting an error "throw new TypeError('JwtStrategy requires a secret or key');"
body: <p>I am trying to make an web application but While trying to run few files I am getting this error:</p>
  
  <pre><code>throw new TypeError('JwtStrategy requires a secret or key');
          ^
  
  TypeError: JwtStrategy requires a secret or key
      at new JwtStrategy (/Users/smitsanghvi/Desktop/project/node_modules/passport-jwt/lib/strategy.js:45:15)
      at module.exports.passport (/Users/smitsanghvi/Desktop/project/config/passport.js:12:18)
      at Object.&lt;anonymous&gt; (/Users/smitsanghvi/Desktop/project/index.js:27:29)
      at Module._compile (module.js:652:30)
      at Object.Module._extensions..js (module.js:663:10)
      at Module.load (module.js:565:32)
      at tryModuleLoad (module.js:505:12)
      at Function.Module._load (module.js:497:3)
      at Function.Module.runMain (module.js:693:10)
      at startup (bootstrap_node.js:191:16)
      at bootstrap_node.js:612:3
  [nodemon] app crashed - waiting for file changes before starting...
  </code></pre>
  
  <p>I did pass key to JWS strategy but still I am getting an error.</p>
  
  <p>passport.js</p>
  
  <pre><code>const jwtStrategy=require('passport-jwt').Strategy;
  const ExtractJwt=require('passport-jwt').ExtractJwt;
  const mongoose=require('mongoose');
  const User=mongoose.model('User');
  const key=require('../config/key');
  
  const options={};
  options.jwtFromRequest=ExtractJwt.fromAuthHeaderAsBearerToken();
  options.secretOrKey=key.secretOrKey;
  
  module.exports=passport=&gt;{
      passport.use(new jwtStrategy(options,(jwt_checking, done)=&gt;{
          console.log(jwt_checking);
          User.findById(jwt_checking.id).then(user=&gt;{
              if(user){
                  return done(null, user);
              }
              return done(null,false);
          })
          .catch(err=&gt;console.log(err))
      }))
  }
  </code></pre>
  
  <p>This is the main file of the application.
  index.js</p>
  
  <pre><code>const express= require('express');
  const mongoose=require('mongoose');
  const bodyParser=require('body-parser');
  const user=require('./route/api/user');
  const userprofile=require('./route/api/userprofile');
  const passport=require('passport');
  const key=require('./config/key');
  
  
  const app=express();
  //body parser middleware
  app.use(bodyParser.urlencoded({extended:false}));
  app.use(bodyParser.json());
  
  //database confid into variable using variable name that I used in key.js of config folder
  const database=require('./config/key').mongoURI;
  
  //connecting to mongodb
  //.then will print connected if successful
  //catch will print error if not
  mongoose.connect(database).then(()=&gt;console.log("connected")).catch(err=&gt;console.log(err));
  
  //passport middleware
  app.use(passport.initialize());
  
  //passport config
  require('./config/passport')(passport);
  
  //gave port number 3000 input to run
  //using route to check the output of user.js and userprofile.sj
  app.use('/api/user',user);
  app.use('/api/userprofile',userprofile);
  //will run at 3000 port on localhost
  const port=process.env.PORT || 3000;
  
  //it will print this in the terminal after npm start or npm run server 
  //this will print the consr port in conlsole
  app.listen(port,()=&gt; console.log('port is:: ${port}'));
  </code></pre>
  
  <p>user.js</p>
  
  <pre><code>const express=require('express');
  const router=express.Router();
  const bcrypt=require('bcryptjs');
  const user=require('../../model/User');
  const jwt=require('jsonwebtoken');
  const key=require('../../config/key');
  const passport=require('passport');
  
  
  router.get('/demo',(req,res)=&gt;res.json({output:"user"}));
  
  //creating route for regsiteration
  //using postman it will get this 
  router.post('/register',(req,res)=&gt;{
      //find if email exists or not.
      user.findOne({email: req.body.email}).then(user=&gt;{
          if(user){
              return res.status(400).json({email:"email is already registered"});
          }
          else{
              //else will creaete new user
              const newUser=new User({
                  name: req.body.name,
                  email:req.body.email,
                  password:req.body.password
              })
  
              //generate salt and hash pass with salt
              bcrypt.genSalt(10,(err,salt)=&gt;{
                  //hashing password
                  bcrypt.hash(newUser.password, salt, (err,hash)=&gt;{
                      if(err) throw err;
                      //after setting hash password will save it
                      newUser.password=hash;
                      newUser.save()
                      //then will return through json
                      .then(user=&gt;res.json(user))
  
                  })
              })
          }
      })
  });
  
  //returning jason web token
  router.post('/login',(req,res)=&gt;{
      const email=req.body.email;
      const password=req.body.password;
      //will find user by email
      //will check if email and pass is present in mlab db
      User.findOne({email}).then(user=&gt;{
          if(!user){
              return res.status(404).json({email:"user doesnt exist"});
      }
      //
              bcrypt.compare(password,user.password).then(isMatch=&gt;{
                  if(isMatch){
                      //user matched
                      //checking will check the details of user
                      const checking={id: user.id,name:user.name}
                      //
                      jwt.sign(checking,key.key1,(err,token)=&gt;{
                          res.json({
                              access:true,
                              token:token
                          })
                      });
  
              }
                      else{
                      return res.status(400).json({password:"password incorrect"});
          }
  
              })
  
      })
  })
  
  router.get(
      '/current',
      passport.authenticate('jwt',{session:false}), 
      (req,res)=&gt;{
      res.json({
          id:req.user.id,
          name:req.user.name,
          email:req.user.email
  
  
  })
      }
  )
  
  
  module.exports=router;
  </code></pre>
  
  <p>All the packages are properly installed. I am not able to solve this issue and eventually the application is getting crashed.</p>