can someone help me to give an example to write this code in a node module with module .exports and how i can use it in another file ?

can someone help me to give an example to write this code in a node module with module .exports and how i can use it in another file ?
 
passport.serializeUser((user, done) => {
done(null, user.id);
});

passport.deserializeUser((id, done) => {
User.findById(id).then((user) => {
done(null, user);
});
});
// set up session cookies
app.use(cookieSession({
maxAge: 24 * 60 * 60 * 1000,
keys: [keys.session.cookieKey]
}));
You already invited:

Tomas

Upvotes from:

module.exports = function(app){

passport.serializeUser((user, done) => {
done(null, user.id);
});

passport.deserializeUser((id, done) => {
User.findById(id).then((user) => {
done(null, user);
});
});

// set up session cookies
app.use(cookieSession({
maxAge: 24 * 60 * 60 * 1000,
keys: [keys.session.cookieKey]
}));

}
You want to export it as a anonymous function
 
module.exports = (app) =>{

passport.serializeUser((user, done) => {
done(null, user.id);
});

passport.deserializeUser((id, done) => {
User.findById(id).then((user) => {
done(null, user);
});
});

// set up session cookies
app.use(cookieSession({
maxAge: 24 * 60 * 60 * 1000,
keys: [keys.session.cookieKey]
}));

}
 
 
 
both are the same
 

If you wanna answer this question please Login or Register