From 25efed90cd6253f551d1df58c1071958ec746d1c Mon Sep 17 00:00:00 2001 From: zarsa Date: Sun, 4 Jun 2023 15:02:18 +0430 Subject: [PATCH] add .env file --- .gitignore | 4 +++- db/data-source.ts | 11 ++++++----- package-lock.json | 41 +++++++++++++++++++++++++++++++++++++++++ package.json | 5 ++--- src/app.module.ts | 2 ++ 5 files changed, 54 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 22f55ad..ea48d65 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,6 @@ lerna-debug.log* !.vscode/settings.json !.vscode/tasks.json !.vscode/launch.json -!.vscode/extensions.json \ No newline at end of file +!.vscode/extensions.json + +.env \ No newline at end of file diff --git a/db/data-source.ts b/db/data-source.ts index 8583d83..fb6a504 100644 --- a/db/data-source.ts +++ b/db/data-source.ts @@ -1,12 +1,13 @@ import { DataSource, DataSourceOptions } from 'typeorm'; +import 'dotenv/config'; export const dataSourceOptions: DataSourceOptions = { type: 'mssql', - host: '193.176.240.223\\sql2017', - port: 1433, - username: 'sa', - password: 'Zar@Sql2017#1397', - database: 'TirebanClub', + host: process.env.DATABASE_HOSTNAME, + port: Number(process.env.DATABASE_PORT), + username: process.env.DATABASE_USERNAME, + password: process.env.DATABASE_PASSWORD, + database: process.env.DATABASE_NAME, entities: ['dist/**/*.entity{.ts,.js}'], synchronize: true, options: { diff --git a/package-lock.json b/package-lock.json index 36cdcc1..5ee1b8e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "UNLICENSED", "dependencies": { "@nestjs/common": "^9.0.0", + "@nestjs/config": "^2.3.2", "@nestjs/core": "^9.0.0", "@nestjs/mapped-types": "*", "@nestjs/platform-express": "^9.0.0", @@ -1705,6 +1706,38 @@ } } }, + "node_modules/@nestjs/config": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/@nestjs/config/-/config-2.3.2.tgz", + "integrity": "sha512-VtGV8PBpxzMzz68kdxTWqPm9v7SYCSZXQ0tC72AMNnjdmU+CVjUSLpEpdnm0XcWHxE1nV6wSI3HZxsATIV4ZxA==", + "dependencies": { + "dotenv": "16.0.3", + "dotenv-expand": "10.0.0", + "lodash": "4.17.21", + "uuid": "9.0.0" + }, + "peerDependencies": { + "@nestjs/common": "^7.0.0 || ^8.0.0 || ^9.0.0", + "reflect-metadata": "^0.1.13", + "rxjs": "^6.0.0 || ^7.2.0" + } + }, + "node_modules/@nestjs/config/node_modules/dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==", + "engines": { + "node": ">=12" + } + }, + "node_modules/@nestjs/config/node_modules/uuid": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz", + "integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/@nestjs/core": { "version": "9.4.2", "resolved": "https://registry.npmjs.org/@nestjs/core/-/core-9.4.2.tgz", @@ -3752,6 +3785,14 @@ "url": "https://github.com/motdotla/dotenv?sponsor=1" } }, + "node_modules/dotenv-expand": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz", + "integrity": "sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==", + "engines": { + "node": ">=12" + } + }, "node_modules/ecdsa-sig-formatter": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", diff --git a/package.json b/package.json index e6a2256..7c2e07b 100644 --- a/package.json +++ b/package.json @@ -21,12 +21,11 @@ "typeorm": "npm run build && npx typeorm -d dist/db/data-source.js", "m:g": "npm run build && npx typeorm migration:generate ./db/migrations/refactoring -d dist/db/data-source.js", "m:r": "npm run typeorm -- migration:run", -"migration:revert": "npm run typeorm -- migration:revert" - - + "migration:revert": "npm run typeorm -- migration:revert" }, "dependencies": { "@nestjs/common": "^9.0.0", + "@nestjs/config": "^2.3.2", "@nestjs/core": "^9.0.0", "@nestjs/mapped-types": "*", "@nestjs/platform-express": "^9.0.0", diff --git a/src/app.module.ts b/src/app.module.ts index cb651cd..32ff0fc 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -6,9 +6,11 @@ import { UsersModule } from './users/users.module'; import { PersonsModule } from './persons/persons.module'; import { GroupsModule } from './groups/groups.module'; import { dataSourceOptions } from 'db/data-source'; +import { ConfigModule } from '@nestjs/config'; @Module({ imports: [ + ConfigModule.forRoot(), TypeOrmModule.forRoot(dataSourceOptions), UsersModule, PersonsModule,