Skip to content

Commit f4bd3e6

Browse files
Add support for .env files
1 parent 801dd6a commit f4bd3e6

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/nhsuk-prototype-kit.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { existsSync } from 'node:fs'
12
import { dirname, join, resolve } from 'node:path'
23
import { cwd } from 'node:process'
34
import { fileURLToPath } from 'node:url'
@@ -17,6 +18,11 @@ export const appPath = cwd()
1718
export const scriptPath =
1819
process.mainModule?.filename ?? join(appPath, 'app.js')
1920

21+
/**
22+
* Environment variables path
23+
*/
24+
export const envPath = join(dirname(scriptPath), '.env')
25+
2026
/**
2127
* NHS prototype kit path
2228
*/
@@ -75,3 +81,8 @@ export const searchPaths = [
7581
join(nhsukFrontendPath, 'dist'),
7682
...modulePaths
7783
]
84+
85+
// Load environment variables (optional)
86+
if (existsSync(envPath)) {
87+
process.loadEnvFile(envPath)
88+
}

lib/nodemon.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { join } from 'node:path'
22

33
import {
44
appPath,
5+
envPath,
56
scriptPath,
67
prototypeKitPath
78
} from './nhsuk-prototype-kit.config.js'
@@ -21,7 +22,7 @@ export default /** @satisfies {NodemonSettings} */ ({
2122
script: scriptPath,
2223
signal: 'SIGINT',
2324
spawn: true,
24-
watch: [join(prototypeKitPath, 'lib'), scriptPath, appPath]
25+
watch: [join(prototypeKitPath, 'lib'), envPath, scriptPath, appPath]
2526
})
2627

2728
/**

0 commit comments

Comments
 (0)