File tree 3 files changed +19
-2
lines changed
3 files changed +19
-2
lines changed Original file line number Diff line number Diff line change 1
1
import { Module } from '@nestjs/common' ;
2
+ import { ConfigModule } from '@nestjs/config' ;
3
+ import config from './config' ;
2
4
3
5
@Module ( {
4
- imports : [ ] ,
6
+ imports : [
7
+ ConfigModule . forRoot ( { isGlobal : true , load : [ config ] } ) ,
8
+ ] ,
5
9
} )
6
10
export class AppModule { }
Original file line number Diff line number Diff line change
1
+ export type Config = {
2
+ port ?: number ;
3
+ }
4
+
5
+ // Define environment variables
6
+ export default ( ) => ( {
7
+ port : process . env . PORT || 3000 ,
8
+ } as Config ) ;
Original file line number Diff line number Diff line change
1
+ import { ConfigService } from '@nestjs/config' ;
1
2
import { NestFactory } from '@nestjs/core' ;
2
3
import {
3
4
FastifyAdapter ,
@@ -11,7 +12,11 @@ async function bootstrap() {
11
12
new FastifyAdapter ( ) ,
12
13
) ;
13
14
14
- await app . listen ( 3000 , '0.0.0.0' ) ;
15
+ // Getting configuration from environment
16
+ const configService = app . get ( ConfigService ) ;
17
+ const port = configService . get ( 'port' ) ;
18
+
19
+ await app . listen ( port , '0.0.0.0' ) ;
15
20
}
16
21
17
22
bootstrap ( ) ;
You can’t perform that action at this time.
0 commit comments