Preheat your oven to 350°F (175°C). Grease and line the bottom of the two 9-inch round cake pans with parchment paper.
In a large mixing bowl, whisk together the flour, granulated sugar, baking powder, baking soda, cinnamon, nutmeg, and salt until well combined.
In a separate bowl, whisk together the vegetable oil and eggs until smooth. Gradually add this wet mixture to the dry ingredients, stirring until just combined.
Fold in the grated carrots, walnuts (if using), and crushed pineapple until evenly distributed.
Divide the batter evenly between the two prepared cake pans. Smooth the tops with a spatula.
Bake in the preheated oven for 25-30 minutes, or until a toothpick inserted in the center comes out clean. Allow the cakes to cool in the pans for about 10 minutes, then transfer them to a cooling rack to cool completely.
While the cakes are cooling, make the cream cheese frosting. In a mixing bowl, beat together the softened cream cheese and butter until creamy and smooth.
Gradually add the powdered sugar and vanilla extract, mixing until well combined.
Once the cakes are completely cooled, place one layer on a serving plate. Spread a generous amount of cream cheese frosting over the top. Place the second cake layer on top and frost the top and sides of the cake as desired.
Slice and serve the cake. Enjoy!