In a large bowl, whisk together the flour, eggs, milk, salt, and nutmeg until you have a smooth batter. Let it rest for 10-15 minutes.
Bring a large pot of salted water to a boil. While waiting for the water to boil, you can start caramelizing the onions. Heat 2 tablespoons of butter in a pan, add the sliced onions, and cook them over medium heat until they turn golden brown and caramelized. Set them aside.
Once the water is boiling, reduce the heat slightly. Place a colander or spätzle maker over the pot and pour a portion of the batter onto it. Use a spatula or the back of a spoon to push the batter through the holes directly into the boiling water. Repeat until you've used all the batter. The spätzle will quickly rise to the surface when they're cooked. Scoop them out with a slotted spoon and transfer them to a large bowl.
Preheat your oven to 350°F (175°C). Grease a baking dish with butter.
To assemble the Käsespätzle, start with a layer of cooked spätzle in the baking dish, followed by a sprinkle of grated cheese and a few spoonfuls of caramelized onions. Repeat the layers until you've used up all the ingredients, ending with a layer of cheese on top.
Bake in the preheated oven for about 20-25 minutes, or until the cheese is melted and bubbly, and the top is golden brown.
Once out of the oven, let it cool for a few minutes, then serve your piping hot Käsespätzle with a sprinkle of salt and pepper to taste. Enjoy!