KY040 rotary encoder - counting within NR

Sorry, I should have looked at the link you posted first. It seems fairly clear from that, assuming the device there is the same as yours. Initially I suggest forgetting about node red and get the code there working from the command line as is shown in the link. Once that is working then you can think about getting the data into node red.
One thing to think about though. He is using polling to read the encoder, which means that if the processor is doing something while the encoder is moving and it is not able to poll for a period greater than 1/96th of a revolution then you will loose position. Personally I would probably stick with the dedicated hardware for the encoder position.