Infections are not always serious, and in many cases, the body can fight the infection on its own. Lymph nodes swell when a person has an infection because the lymph fluid traps harmful bacteria, viruses, and waste products. The nodes also contain immune cells.