Preheat the oven to 350°F (175°C). Grease and flour the two cake pans.
In a large mixing bowl, whisk together the flour, sugar, baking powder, baking soda, cinnamon, nutmeg, and salt until well combined.
In another bowl, whisk together the vegetable oil and eggs until smooth. Stir in the grated carrots and drained crushed pineapple.
Gradually add the wet mixture to the dry ingredients, mixing gently until just combined. Fold in the chopped nuts if using.
Divide the batter evenly between the prepared cake pans.
Bake in the preheated oven for 30-35 minutes, or until a toothpick inserted into the center of the cakes comes out clean.
Allow the cakes to cool in the pans for 10 minutes, then turn them out onto a cooling rack to cool completely.
Meanwhile, prepare the cream cheese frosting. In a mixing bowl, beat together the softened cream cheese and butter until smooth and creamy.
Gradually add the powdered sugar and vanilla extract, mixing until fully incorporated. 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 frosting on top. Place the second layer on top and frost the top and sides of the entire cake.
Slice and serve. Enjoy!