Preheat your oven to 350°F (175°C). Line a muffin tin with cupcake liners.
In a mixing bowl, whisk together the flour, baking powder, baking soda, salt, cinnamon, and nutmeg.
In another large bowl, mix the granulated sugar, brown sugar, and vegetable oil until well combined. Add the eggs one at a time, mixing well after each addition.
Stir in the grated carrots, crushed pineapple, walnuts (if using), and vanilla extract into the wet mixture.
Gradually add the dry ingredient mixture to the wet ingredients, stirring gently until just combined. Be careful not to overmix.
Fill each cupcake liner about two-thirds full with the batter.
Bake in the preheated oven for 18-20 minutes, or until a toothpick inserted into the center comes out clean.
Remove cupcakes from the oven and let them cool in the pan for 5 minutes, then transfer them to a wire rack to cool completely.
While the cupcakes are cooling, prepare the cream cheese frosting. In a mixing bowl, beat the softened cream cheese and butter together until smooth and creamy.
Gradually add the powdered sugar and vanilla extract, continuing to mix until the frosting is light and fluffy.
Once the cupcakes are completely cooled, frost them with the cream cheese frosting using a spatula or piping bag.