I am following a course for a Node js ( among other things ) , in this course passport.js is used. In index.js file i required the configuration module that we created for passport.js to use “Google Strategy” , and in my routes i required the global instance for passport.js and i used it to authenticate user via oauth of google .
my question is how the passport code in my routes knows that i am using google strategy and their configs like ClientID and ClientSecret even if i am not using the same instance of passport.js in my config file , to make things clear here is the code :
Index.js
const express = require("express");
require("./services/passport");
const app = express();
require("./routes/authRoutes")(app);
app.listen(5000);
passport.js inside my services folder
const passport = require("passport");
const GoogleStrategy = require("passport-google-oauth20").Strategy;
const keys = require("../config/keys");
passport.use(
new GoogleStrategy(
{
clientID: keys.googleClientID,
clientSecret: keys.googleClientSecret,
callbackURL: "/auth/google/callback",
},
(accessToken, refreshToken, profile, done) => {
console.log("accessToken", accessToken);
console.log("refreshToken", refreshToken);
console.log("profile", profile);
console.log("done", done);
}
)
);
authRoute.js
const passport = require("passport");
// here i am importing the global passport , how this instance knows that i used google strategy
// in my configs and their configs like googleClientID ...ect ?
module.exports = (app) => {
app.get(
"/auth/google",
passport.authenticate("google", {
scope: ["profile", "email"],
})
);
app.get("/auth/google/callback", passport.authenticate("google"));
};

