Preheat your oven to 350°F (175°C). Grease and flour two 9-inch round cake pans.
In a large bowl, whisk together the flour, sugar, baking powder, baking soda, cinnamon, nutmeg, and salt.
In another bowl, combine the oil and eggs, and beat until well mixed. Stir in the grated carrots, crushed pineapple, walnuts or pecans (if using), and vanilla extract.
Gradually add the dry ingredients to the wet ingredients, mixing until just combined. Do not overmix.
Divide the batter evenly between the prepared cake pans. Bake for 25-30 minutes, or until a toothpick inserted in the center comes out clean.
Allow the cakes to cool in the pans for 10 minutes, then transfer to wire racks to cool completely.
While the cakes are cooling, prepare the cream cheese frosting. In a medium bowl, beat together the softened cream cheese and butter until smooth. Gradually add the powdered sugar and vanilla extract, mixing until creamy. Add milk as needed to achieve desired consistency.
Once the cakes are completely cool, place one layer on a serving plate. Spread a layer of cream cheese frosting on top, then place the second layer on top and frost the top and sides of the cake.