Developing a NodeMCU based firmware for the ESP8266 can be quite annoying. If you cause a bug, the ESP will answer with a hardreset.
If you cause the bug in the init.lua which will be executed on startup, the ESP will boot again, executing the initialization script again. With that it will hardreset, execute init.lua again, hardreset, execute…. And so on. The only way out will be erasing the flash and flashing NodeMCU again.
But: There is simple solution. Don’t use a init-file in the development phase. Name it init_start.lua or similiar and use the dofile-command to execute it manually. As soon as your development is done and everthing is working, you can rename it and make use of the automatic execution.
Took me some failures to learn the trick :-)