NodeMcu interfacing with Arduino Mega

Alright, //to be uploaded on MEGA, as a master sender
#include <Wire.h>
void setup()
{
Wire.begin();
}
void loop() {
Wire.beginTransmission(8);
Wire.write(“1”);
Wire.endTransmission();
delay(100); }

//to be uploaded on NODE, as a slave reciever.
#include<Wire.h>
void setup() {
Serial.begin(9600);
Wire.begin(8);
//Wire.onReceive(recEvent);
}
void recEvent(int bytes)
{ while(Wire.available()>0)
{ char x=Wire.read();
Serial.print(x);}
Serial.println(); }
void loop() {
Wire.onReceive(recEvent); delay(100);
//Serial.println(Wire.read());
}

These are the codes, i have uploaded but NodeMcu is not reading any data.
But if i interchange the codes, the work perfectly fine.
Plz help.

But if i interchange the codes, the work perfectly fine.

Why does loop() keep registering the same handler for when there is Wire data to read? That needs to be done ONCE.

It's ONE statement per line.

Put every { on a line BY ITSELF.
Put every } on a line BY ITSELF.
Use Tools + Auto Format before posting code.
Use code tags when posting code.