File tree Expand file tree Collapse file tree 1 file changed +25
-19
lines changed
Expand file tree Collapse file tree 1 file changed +25
-19
lines changed Original file line number Diff line number Diff line change 11import express from 'express' ;
2- function loggerMiddleware (
3- request : express . Request ,
4- response : express . Response ,
5- next : express . NextFunction
6- ) {
7- console . log ( `${ request . method } ${ request . path } ` ) ;
8- next ( ) ;
9- }
2+ export class App {
3+ constructor ( public port : number ) { }
104
11- const app = express ( ) ;
12- app . use ( loggerMiddleware ) ;
5+ loggerMiddleware (
6+ request : express . Request ,
7+ response : express . Response ,
8+ next : express . NextFunction
9+ ) {
10+ console . log ( `${ request . method } ${ request . path } ` ) ;
11+ next ( ) ;
12+ }
1313
14- const port = 3000 ;
15- app . get ( '/' , ( req , res ) => {
16- res . send ( 'Ts server is running fine ...' ) ;
17- } ) ;
18- app . listen ( port , ( err ) => {
19- if ( err ) {
20- return console . error ( err ) ;
14+ createApp ( ) {
15+ const app : express . Application = express ( ) ;
16+ app . use ( this . loggerMiddleware ) ;
17+ return app ;
2118 }
22- return console . log ( `server is listening on ${ port } ` ) ;
23- } ) ;
19+
20+ startServer ( ) {
21+ const app = this . createApp ( ) ;
22+ app . listen ( this . port , ( err : any ) => {
23+ if ( err ) {
24+ return console . error ( err ) ;
25+ }
26+ return console . log ( `server is listening on ${ this . port } ` ) ;
27+ } ) ;
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments