After running the 'npm rebuild' command all page requests trigger twice

A couple of months ago, I was working on a side project using Node and Express. I had to run npm rebuild because the node version of my system was not in sync with that of my application. But now every time I go to a page it loads all the functions twice (I think on click and on load). Here’s a copy of all of the functions related to my landing page.

index.js:

app.get("/", userCheckup, guessLoad); 

userCheckup:

exports.userCheckup = (req, res, next) => {  var user = auth.currentUser;  var authenticated;  if(user) {    authenticated = true;    res.locals.authenticated = authenticated;    res.locals.uid = user.uid;    res.locals.email = user.email;    next();  } else {    authenticated = false;    res.locals.authenticated = authenticated;    next();  } } 

guessLoad:

exports.guessLoad = async(req, res) => {   const user = res.locals.uid;   console.log("aagaaaint");    var randNr, randId;    var getCount = await db.collection("recipeCount").doc("count").get();   randNr = Math.floor(Math.random() * getCount.data().count);    var getIds = await db.collection("recipeCount").doc("ids").get();   if(getIds.data().idList != null) {     randId = getIds.data().idList[randNr];      var getRecipe = await db.collection("recipes").doc(randId).get();     if(getRecipe.exists != true) {       res.render('noRecipeFound', {uid : res.locals.uid})     }     var randomRecipe = new Object();     randomRecipe.id = randId;     randomRecipe.country = getRecipe.data().country.toLowerCase();     randomRecipe.saves = getRecipe.data().saves;     randomRecipe.cookingTime = getRecipe.data().cookingTime;     randomRecipe.servings = getRecipe.data().servings;     randomRecipe.dish = getRecipe.data().dish;     randomRecipe.image = getRecipe.data().image;     randomRecipe.description = getRecipe.data().description;     randomRecipe.user = getRecipe.data().user;      var ingredients = getRecipe.data().ingredients;     var ingredientsPreview = []     for (var i = 0; i < ingredients.length && i < 3; i++) {       ingredientsPreview.push(" " + ingredients[i].ingredient);     }     randomRecipe.ingredients = ingredientsPreview;      var alreadySaved = false;     if(typeof user !== "undefined") {       const getUser = await db.collection('users').doc(user).get();       const userSaves = getUser.data().saved;       for(id of userSaves) {         if(id == randomRecipe.id) {           alreadySaved = true;         }       }     }      // save cookie     var cookies = cookie.parse(req.headers.cookie || '');     res.cookie('previous', randId)         var last = false;     if(Object.keys(cookies).length === 0 && cookies.constructor === Object) {       var last = true;     }     console.log(cookies);     console.log("request arrived for URL", req.url);      res.render("landing", {uid : res.locals.uid, randomRecipe : randomRecipe, alreadySaved : alreadySaved})   } }  
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.