Nephridia, the plural of nephridium, is a unit of the excretory system in many primitive invertebrates that is responsible for expelling the metabolic wastes of the organism. When this structure evolved it allowed for the specialization of tissues within the excretory system and eliminated the need for all of an organism's cells to be involved in the process of excreting waste by being in contact with water.
Earthworms are more advanced invertebrates when compared to more primitive organisms such as ribbon worms. This advancement is demonstrated in the segmented structure of the worm's body.
Earthworms have metanephridia, a more complex version of the construct that is generally oriented in pairs throughout the earthworm's body. This structure directs the metabolic waste through the body cavity. As it moves, cilia absorbs cavity fluids while specialized tubule cells absorb any useful nutrients that remain in the waste.
Once the metabolic waste, toxins, fluids, and useless hormones that are filtered out of the body through the nephridia have been fully processed through the body cavity, what remains is passed out of the earthworm's body through a structure called the nephridiopore.
The metanephridia structure is also responsible for taking the primary urine that is produced by filtering the blood and reabsorbing select nutrients, thereby filtering it into secondary urine so it can be expelled.