Arduino mega and nodemcu esp2866-esp12e connect together for wifi

You can program the ESP with the Arduino IDE using the Arduino Esp core. Use one of the serial ports to communicate between the Mega and ESP.