NodeMCU ESP8266 12E loses code after power is reconnected
D3 (GPIO0) and D4 (GPIO2) both need to be high on startup for the user program to be executed. The relay board connected to those pins are preventing a sufficient high on those pins. 

If you need to use those pins then try using a stronger pull-up resistor on those pins. Try 330-470 ohms. 

Either that or you will need to add additional circuitry between the port pins and the relay driver. Also please be aware that this will place a high on the relay driver input and will try to turn on the relays. Your powerup conditions may not be what you expect.