Last active
May 9, 2020 05:32
-
-
Save leonardofreitass/10bf4d28081f443579271e9358b5bcc8 to your computer and use it in GitHub Desktop.
Express Server using TypeScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Server { | |
public app: express.Application; | |
public config: Config; | |
public static bootstrap(): Server { | |
return new Server(); | |
} | |
constructor() { | |
this.app = express(); | |
this.setup(); | |
this.routes(); | |
} | |
setup(){ | |
this.app.use(morgan(‘combined’)); | |
} | |
routes(){ | |
this.app.use(MyRoutes); | |
} | |
start(){ | |
const server = this.app.listen(3030, () => { | |
const address = server.address(); | |
logger.info(`Server running at: ${address.address}:${address.port}`); | |
}); | |
return server; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment