Thursday, 25 May 2017

node keeps executing deleted code after resetting the server?

My node.js app had this function declared:

//deletes a user and its related files.
function deleteUser(userToDelete)
{
  if (userToDelete == null || userToDelete == {})
  {
    return { success: false, message: 'error deleting user 1.'};
}

{
    return { success: false, message: 'error deleting user 2.'};
}
  // delete the entry from the database
  User.findOneAndRemove({ email: userToDelete}, function(err, filesList) {
    if (err)
    {

      return { success: false, message: 'error deleting user.3'};
    }
  });
  //delete related files

  UserFile.remove({owner:userToDelete}, function(err,filesList){
    if (err)
    {
      return { success: false, message: 'user deleted. Error deleting related files.'};
    }
      return { success: true, message: 'user deleted.'};
  });


};

I noticed that this part shouldn't be there:

{
    return { success: false, message: 'error deleting user 2.'};
}

So I deleted it, saved the file, closed node, and run it again. However, the api endpoint that calls that function keeps returning { success: false, message: 'error deleting user 2.'}. I've made sure that this string of JSON is not present in any other place of my codebase, there is no code that can be ran that produces this result, yet it keeps being executed. What is happening? Why is old removed code being executed, is there any kind of caching I'm not aware of that survives resetting node?



via kace91

No comments:

Post a Comment