refactor -> function in lib/server.js and server management in app.js