reorganized nodejs portion of code