Skip to content

Commit

Permalink
feat: enable to specify dotenv file along with other config params
Browse files Browse the repository at this point in the history
  • Loading branch information
acro5piano committed Mar 18, 2024
1 parent 93169bc commit 5df8658
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/cli.ts
Expand Up @@ -4,11 +4,17 @@ import path from 'path'
import { promises as fs } from 'fs'
import { Pool } from 'pg'

const dotenvPath = process.env.DOTENV_CONFIG_PATH || '.env'

/**
* Load Dotenv if the module exists.
*/
try {
require('dotenv').config()
require('dotenv').config({
debug: !!process.env.DOTENV_CONFIG_DEBUG,
path: dotenvPath,
encoding: process.env.DOTENV_CONFIG_ENCODING,
})
} catch {}

const { DATABASE_URL } = process.env
Expand All @@ -18,7 +24,7 @@ if (!DATABASE_URL) {
Please specify DATABASE_URL to run this CLi. Try the following:
- Run \`DATABASE_URL=postgres://user:password@host:port/database && npm run kysely-migration-cli\`
- Place .env file containing \`DATABASE_URL=postgres://user:password@host:port/database\`
- Place ${dotenvPath} file containing \`DATABASE_URL=postgres://user:password@host:port/database\`
`
console.log(hint)
process.exit(1)
Expand Down

0 comments on commit 5df8658

Please sign in to comment.