Preheat oven to 350°F (175°C). Grease and flour two 9-inch round pans (or one 9x13-inch pan).
In a bowl, whisk together flour, baking soda, cinnamon, nutmeg, and salt.
In another bowl, whisk sugars, oil, eggs, and vanilla until smooth.
Add dry ingredients to wet mixture and stir until just combined.
Fold in grated carrots, pineapple, and nuts (if using). Batter will be thick.
Pour into pans and bake 30–35 minutes (round) or 40–45 minutes (rectangular). Check with a toothpick.
Cool completely before frosting.
For frosting: beat cream cheese and butter until smooth, add powdered sugar and vanilla, and beat until fluffy.
Frost the cooled cake and chill before serving.