title: How Passport Strategy works behind the Scene
body: <p>I was trying to comprehend how passport strategy is working. </p>
  
  <p>Consider these api routes which I am using to authenticate.</p>
  
  <pre><code>  router.get("/google",  passport.authenticate('google', { scope: ['profile', 'email'] }));
    router.get("/google/callback", passport.authenticate('google'), (req, res) =&gt; {
        res.redirect("http://localhost:3000/")
    })
  </code></pre>
  
  <p>And this is the passport strategy</p>
  
  <pre><code>const passport = require('passport')
  const GoogleStratergy = require('passport-google-oauth20')
  const keys = require("./key.js")
  const User = require("../models/user-model.js")
  
  passport.serializeUser((user, done) =&gt; {
      done(null, user.id) 
  })
  
  passport.deserializeUser((id, done) =&gt; {
      User.findById(id).then((user) =&gt; {
          done(null, user) //pass it in req of our routes
      })
  })
  
  passport.use(
      new GoogleStratergy({
      //Options for the stratergy 
          callbackURL: "/auth/google/callback", 
          clientID: keys.google.clientID,
          clientSecret: keys.google.clientSecret
      }, (accessToken, refreshToken, profile, done) =&gt; {
  
  
          User.findOne({userId: profile.id }).then((currentUser) =&gt; {
              if (currentUser) {
                  done(null, currentUser)
              } else {
                      //Changing Image String
                      let  oldURL=  profile.photos[0]["value"]
                      let newURL =  oldURL.substr(0,  oldURL.length-2);
                      newURL = newURL + "250"
                  //Creating Mongoose Database
                      new User({
                          username: profile.displayName,
                          userId: profile.id,
                          image: newURL,
                          email: profile.emails[0]["value"]
                      }).save().then((newUser) =&gt; {
                          console.log("new user created", newUser)
                          done(null, newUser)
                     })
              }
  
          })
  
      })
  )
  </code></pre>
  
  <p>Now, I think I understand what is happening here, but one thing I am unable to comprehend here is.. </p>
  
  <p>How is </p>
  
  <pre><code>passport.use(
      new GoogleStratergy({
      //Options for the stratergy 
  </code></pre>
  
  <p>being called here? I mean I don't see any export statements, so how is it linked with out Node App? or how does passport knows behind the scene about the location of our google strategy **  </p>
  
  <p>Also, Just to confirm, after we pass done from our passport.use? it goes to serialize?</p>