server.js refactoring