Controlling 12V water pump with NodeMCU – circuit design review
The application looks like turning on the motor depending on the data of the moister sensor.


what is the point of switching on and off moisture sensor , instead you can power the sensor directly to 3.3v.
Coming to flashing of code into nodemcu , you cannot connect USB to board when there is external power supply. You have to remove external power supply and connect USB to flash the code. There is another way called OTA(over through air) where you can flash code into nodemcu without using USB.The host computer should connect to the nodemcu through WIFI and flashing can be done through air. Explore about OTA on nodemcu.