In a large mixing bowl, combine the flour, salt, and nutmeg (if using). Create a well in the center and crack in the eggs. Add the milk and stir until the mixture forms a smooth, thick batter.
Bring a large pot of salted water to a boil. Using a Spaetzle maker or a colander with large holes, press the batter into the boiling water. Cook until the Spaetzle floats to the surface, then remove with a slotted spoon and set aside.
In a large skillet, melt the butter over medium heat. Add the sliced onions and cook until caramelized, about 15-20 minutes, stirring occasionally.
Preheat your oven to 350°F (175°C). In a greased baking dish or cast-iron skillet, layer the cooked Spaetzle with the caramelized onions and grated cheese. Start with a layer of Spaetzle, then onions, then cheese, and repeat until all ingredients are used, finishing with a layer of cheese on top.
Bake in the preheated oven for 15 minutes, or until the cheese is melted and bubbly. If desired, turn on the broiler for the last 2-3 minutes to brown the top.
Remove from the oven, top with crispy fried onions (if using), and serve hot.