Refactory this to standalone nodejs package.