Connection to database ok with env vars
This commit is contained in:
parent
38c1bb4650
commit
0d194b3c68
|
@ -11,6 +11,9 @@ yarn-debug.log*
|
|||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
#env
|
||||
.env*
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
"license": "UNLICENSED",
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^8.0.0",
|
||||
"@nestjs/config": "^1.1.6",
|
||||
"@nestjs/core": "^8.0.0",
|
||||
"@nestjs/platform-express": "^8.0.0",
|
||||
"@nestjs/sequelize": "^8.0.0",
|
||||
|
@ -1341,6 +1342,22 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@nestjs/config": {
|
||||
"version": "1.1.6",
|
||||
"resolved": "https://registry.npmjs.org/@nestjs/config/-/config-1.1.6.tgz",
|
||||
"integrity": "sha512-HYizKt6Dr6gcZl8FmZbTfQxP0MG8oXMh+gVFT0XCwYDAq26BOKyhPsIxrKsryicVeKViRgetCUhlJY9EqaekZA==",
|
||||
"dependencies": {
|
||||
"dotenv": "10.0.0",
|
||||
"dotenv-expand": "5.1.0",
|
||||
"lodash": "4.17.21",
|
||||
"uuid": "8.3.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@nestjs/common": "^7.0.0 || ^8.0.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rxjs": "^6.0.0 || ^7.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@nestjs/core": {
|
||||
"version": "8.2.5",
|
||||
"resolved": "https://registry.npmjs.org/@nestjs/core/-/core-8.2.5.tgz",
|
||||
|
@ -3522,6 +3539,19 @@
|
|||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
|
||||
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==",
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv-expand": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-5.1.0.tgz",
|
||||
"integrity": "sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA=="
|
||||
},
|
||||
"node_modules/dottie": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.2.tgz",
|
||||
|
@ -10262,6 +10292,17 @@
|
|||
"uuid": "8.3.2"
|
||||
}
|
||||
},
|
||||
"@nestjs/config": {
|
||||
"version": "1.1.6",
|
||||
"resolved": "https://registry.npmjs.org/@nestjs/config/-/config-1.1.6.tgz",
|
||||
"integrity": "sha512-HYizKt6Dr6gcZl8FmZbTfQxP0MG8oXMh+gVFT0XCwYDAq26BOKyhPsIxrKsryicVeKViRgetCUhlJY9EqaekZA==",
|
||||
"requires": {
|
||||
"dotenv": "10.0.0",
|
||||
"dotenv-expand": "5.1.0",
|
||||
"lodash": "4.17.21",
|
||||
"uuid": "8.3.2"
|
||||
}
|
||||
},
|
||||
"@nestjs/core": {
|
||||
"version": "8.2.5",
|
||||
"resolved": "https://registry.npmjs.org/@nestjs/core/-/core-8.2.5.tgz",
|
||||
|
@ -11959,6 +12000,16 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"dotenv": {
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
|
||||
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q=="
|
||||
},
|
||||
"dotenv-expand": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-5.1.0.tgz",
|
||||
"integrity": "sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA=="
|
||||
},
|
||||
"dottie": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.2.tgz",
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^8.0.0",
|
||||
"@nestjs/config": "^1.1.6",
|
||||
"@nestjs/core": "^8.0.0",
|
||||
"@nestjs/platform-express": "^8.0.0",
|
||||
"@nestjs/sequelize": "^8.0.0",
|
||||
|
|
|
@ -2,23 +2,29 @@ import { Module } from '@nestjs/common';
|
|||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { SequelizeModule } from '@nestjs/sequelize';
|
||||
|
||||
import { User } from './users/user.model';
|
||||
import { UsersModule } from './users/users.module';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
SequelizeModule.forRoot({
|
||||
dialect: 'mysql',
|
||||
host: 'localhost',
|
||||
port: 3306,
|
||||
username: 'root',
|
||||
password: 'root',
|
||||
database: 'test',
|
||||
models: [
|
||||
User
|
||||
],
|
||||
autoLoadModels: true,
|
||||
synchronize: true
|
||||
ConfigModule.forRoot({
|
||||
cache: true,
|
||||
}),
|
||||
SequelizeModule.forRootAsync({
|
||||
imports: [ConfigModule],
|
||||
useFactory: (configService: ConfigService) => ({
|
||||
dialect: 'mysql',
|
||||
host: configService.get("DB_HOST", "localhost"),
|
||||
port: configService.get("DB_PORT", 3306),
|
||||
username: configService.get("DB_USER", "root"),
|
||||
password: configService.get("DB_PASS", ""),
|
||||
database: configService.get("DB_NAME", "test"),
|
||||
autoLoadModels: true,
|
||||
}),
|
||||
inject: [ConfigService],
|
||||
}),
|
||||
UsersModule
|
||||
],
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
await app.listen(3000);
|
||||
const configService = app.get(ConfigService);
|
||||
|
||||
await app.listen(configService.get("APP_PORT", 3000));
|
||||
}
|
||||
bootstrap();
|
||||
|
|
Loading…
Reference in New Issue