Skip to content

Instantly share code, notes, and snippets.

@leonardofreitass
Last active May 9, 2020 05:32
Show Gist options
  • Save leonardofreitass/10bf4d28081f443579271e9358b5bcc8 to your computer and use it in GitHub Desktop.
Save leonardofreitass/10bf4d28081f443579271e9358b5bcc8 to your computer and use it in GitHub Desktop.
Express Server using TypeScript
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