Refactor as a node lib