The “2” in the code above means GPIO Pin 2. This is not the same as the pin that’s labelled “D2” on the board. The Blue LED on the board is connected to GPIO2 and is active (lit) when the pin is pulled LOW.
See this diagram for the mapping of GPIO numbers to pin labels: