With invertebrates, ganglia often do the work of a brain. In these cases, like the earthworm, there is a ganglion above the gut at the front. This is linked to another under the gut by nerve fibres running down each side of the gut. The rest of the central nervous system runs under the gut. This type of arrangement in found in a number of invertebrate phyla, and contrasts with the vertebrates, who have their spinal cord above (dorsal to) their gut.
Ganglion Facts for Kids. Kiddle Encyclopedia.