NodeMCU vin pin(5v) is not working
You’ve probably switched some wires.
Relay Connection with Arduino, usually takes 3 Pins:

VCC / In (5v)
Signal (Data) - [D2] Pin On your sketch.
Ground

It is that simple.
Some recommendations apart from your question:

Make sure to know how your relay starts.
That is: Starts Always On or Always Off.

On your sketch (relay initialisation); set the initial relay state before defining its function as OUTPUT.


...
digitalWrite(relayPin; LOW);
PinMode(relayPin, OUTPUT);

...

Ensure the wires are properly connected to avoid wasting time understanding why the relay doesn’t work.
Special attention to Ground Wiring.

Note: Depending on your schematic; You may require to bridge your Grounds.