I am just starting out with electronics. I got a Arduino Mega 2560 board and am able to do simple things like blink. Now I want to start a project on IoT and want to connect this board with internet. I got some leads here. While googling ESP8266, I came across NodeMCU which has a processor too. I already have Arduino, so can I use only the wifi module of NodeMCU and connect it to Arduino?
NodeMCU already has a processor built in with the WiFi so you don't need a separate processor. If you just want to add WiFi to your Arduino board use an ESP8266 board connected to the Arduino. That is essentially the WiFi part of NodeMCU.
I went through almost the exact same thing you are going through when I was looking at the ESP8266 boards (the NodeMCU is one of those). I too discovered that the NodeMCU is a micro computer in itself, even more powerful than the Arduino UNO!
You can even code the NodeMCU using the Arduino IDE. As has been said previously, I'd use your NodeMCU directly to accomplish what you want to do.