NodeMCU has on analog channel which is configured to read the System voltage, we can configure it to sample the external pin.
The ADC seems a bit jumping around for constant voltages as well, so it is better to take average of several readings if you are doing something serious with it.
adc.force_init_mode(mode) allows to set the modes.
The modes for the ADC are
adc.INIT_ADC for sampling external pin
adc.INIT_VDD33 gives the system voltage
adc.read(0) to sample the external pin, adc.readvdd33() to read the system voltage. You have to set the node in correct mode before you call the corresponding methods. You will get 65535 if the node is not in correct mode.
Using the ADC in NodeMCU
print("ADC Config changed,Restarting the node")
return -- don't bother continuing, the restart is scheduled
val = adc.read(0)
The following shows the result of adc.read(0) when the A0 is connected to Ground.