nodejs refactoring