Skip to content

Commit

Permalink
Fix loadEnv incorrectly loading the .env route
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantGeekDev committed Jan 4, 2024
1 parent 8b564af commit 0b32468
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"trailingComma": "none",
"trailingComma": "all",
"tabWidth": 2,
"semi": false,
"singleQuote": true,
Expand Down
32 changes: 32 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@
"license": "GPL-3.0-or-later",
"dependencies": {
"@grammyjs/i18n": "^0.5.1",
"debug": "^4.3.4",
"dotenv": "^16.0.1",
"grammy": "^1.10.1",
"mongodb": "^4.9.1"
},
"devDependencies": {
"@commitlint/cli": "^18.4.3",
"@commitlint/config-conventional": "^18.4.3",
"@types/debug": "^4.1.12",
"@types/node": "^18.7.4",
"@types/pg": "^8.6.5",
"@typescript-eslint/parser": "^6.7.3",
Expand Down
5 changes: 4 additions & 1 deletion src/config/app.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// TODO: Use path aliases
import { loadEnv } from '../helpers/load-env.js'
import { validateEnv } from '../helpers/validate-env.js'
import { startBot } from './bot.js'
import { connectToDb } from './database.js'
import debugCreator from 'debug'

const debug = debugCreator('app:')

export async function startApp() {
debug('Starting app...')
try {
loadEnv()
validateEnv(['TELEGRAM_TOKEN', 'DB_CONNECTION_STRING'])
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/load-env.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import dotenv from 'dotenv'
import { resolvePath } from './resolve-path.js'

export function loadEnv(configPath = '.env') {
export function loadEnv(configPath = '../../.env') {
const fullPath = resolvePath(import.meta.url, configPath)
dotenv.config({
path: fullPath
path: fullPath,
})
}
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { startApp } from './config/app.js'
import debugCreator from 'debug'

await startApp()
console.debug('App started')
const debug = debugCreator('index:')

debug('Starting App')
startApp()
debug('App started')

0 comments on commit 0b32468

Please sign in to comment.