christmas/config/secret/index.js

14 lines
393 B
JavaScript
Raw Normal View History

2020-11-01 19:24:40 -08:00
const { nanoid } = require('nanoid')
2020-11-08 13:54:08 -08:00
const path = require('path')
const fs = require('fs')
2018-11-22 15:42:19 -08:00
2020-11-08 13:54:08 -08:00
const secretFilePath = path.join((process.env.SECRET_DIRNAME ? process.env.SECRET_DIRNAME : __dirname), 'secret.txt')
2018-11-22 15:42:19 -08:00
try {
2020-11-08 13:54:08 -08:00
module.exports = fs.readFileSync(secretFilePath).toString()
2018-11-22 15:42:19 -08:00
} catch (_) {
2020-11-08 13:54:08 -08:00
const secret = nanoid(128)
fs.writeFileSync(secretFilePath, secret)
module.exports = secret
}