Nodemcu problem when electricity cut off and come back

What @Gunner said. Additionally its good to know that

  1. relays usually are active when the pin is LOW
  2. esps after reboot usually go up (for 100ms) and then LOW in default.

What I do is initialize all my pins on setup (exactly for those kinds of cases as you describe) so from my setup() function:
pinMode(HEATER_RELAY_PIN_1, OUTPUT); // Set ESP pin to output to the relay
digitalWrite(HEATER_RELAY_PIN_1, HIGH); // activate = LOW, deactivate = HIGH

beyond that you can use e.g. sync with the server as gunner described.

edit: this is also very helpful!