Auto-generate .env on first run if not present

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
nickandClaude Sonnet 4.6 committed 2026-06-19 21:45:32 -07:00
1 parent 5391827519
commit 2a1d4f6728
1 file changed
+16 -2
+16 -2
View File
@@ -1,13 +1,27 @@
import 'dotenv/config'
import dotenv from 'dotenv'
import express from 'express'
import axios from 'axios'
import { readFileSync, writeFileSync } from 'fs'
import { existsSync, readFileSync, writeFileSync } from 'fs'
import { randomUUID, randomBytes, createCipheriv, createDecipheriv } from 'crypto'
import path from 'path'
import { fileURLToPath } from 'url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
if (!existsSync(path.join(__dirname, '.env'))) {
const encryptionKey = randomBytes(32).toString('hex')
const adminPassword = randomBytes(16).toString('hex')
writeFileSync(
path.join(__dirname, '.env'),
`ENCRYPTION_KEY=${encryptionKey}\nADMIN_PASSWORD=${adminPassword}\nPORT=3000\n`
)
console.log('No .env file found — generated one with a new ENCRYPTION_KEY and ADMIN_PASSWORD.')
console.log(`ADMIN_PASSWORD: ${adminPassword}`)
console.log('Save this password — you will need it to register users via the web UI.')
}
dotenv.config()
// --- Encryption setup ---
const ENCRYPTION_KEY_HEX = process.env.ENCRYPTION_KEY