refactor index.js for export, server resetting in test cases