Safer check for window so node doesn't explode

if(window) causes an error in node since the var doesn't exist. Using this method is safer and prevents node from exploding.