[#54172542] refactor to extract most code from server.js to a module