on an ESP8266 GPIO 4 is D2, so actually D2 = 4.
To confirm, plug in the nodeMCU and see the result of
Serial.prinln(D2, DEC);
So true. (actually none of the GPIO pins on that side of the board are usable)
should be
OneWire oneWire(D6); // pin D6
or
OneWire oneWire(12); // pin D6