- Preheat the oven to 350°F (175°C). Grease a 9x13-inch baking pan and set aside. 
- In a large mixing bowl, whisk together the flour, sugar, baking powder, baking soda, cinnamon, nutmeg, and salt. 
- In another bowl, combine the vegetable oil, eggs, grated carrots, crushed pineapple, walnuts (if using), and vanilla extract. Mix until well combined. 
- Gradually add the wet ingredients to the dry ingredients, stirring until just combined. Do not overmix. 
- Pour the batter into the prepared baking pan and spread it evenly. Bake for 30-35 minutes or until a toothpick inserted in the center comes out clean. 
- Allow the bars to cool in the pan for about 15 minutes, then transfer to a wire rack to cool completely. 
- While the bars 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 well combined. If the frosting is too thick, add milk one tablespoon at a time until the desired consistency is reached. 
- Once the bars are completely cooled, spread the cream cheese frosting evenly over the top. Cut into squares and serve.