Prepare the Green Beans:
Bring a large pot of salted water to a boil. Add the green beans and blanch for 3-4 minutes until tender but still crisp. Drain and set aside.
Make the Cream Sauce:
In a large skillet, melt the butter over medium heat. Add the chopped onion and garlic, if using, and sauté until soft and fragrant, about 2-3 minutes. Stir in the flour to form a roux and cook for 1-2 minutes, stirring constantly.
Add Milk or Cream:
Gradually whisk in the milk or heavy cream, continuing to stir until the sauce thickens, about 3-4 minutes. Season with salt and pepper to taste.
Combine and Cook:
Add the blanched green beans to the skillet, tossing them in the sauce until well-coated. Cook for another 2-3 minutes until the beans are heated through and the sauce clings to them.
Serve:
Transfer the creamed green beans to a serving dish, sprinkle with grated Parmesan cheese if desired, and serve hot.