christmas/config/secret/index.js

13 lines
399 B
JavaScript
Raw Normal View History

2020-11-01 19:24:40 -08:00
const { nanoid } = require('nanoid')
2018-11-22 15:42:19 -08:00
const path = require('path');
const fs = require('fs');
2019-08-19 07:49:21 -07: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 {
module.exports = fs.readFileSync(secretFilePath).toString();
} catch (_) {
2020-11-01 19:24:40 -08:00
const secret = nanoid(128);
2018-11-22 15:42:19 -08:00
fs.writeFileSync(secretFilePath, secret);
module.exports = secret;
}