refactor the logic for downloadNpm