christmas/config/secret/index.js
2020-10-30 12:11:20 -04:00

13 lines
No EOL
394 B
JavaScript

const { v4: uuid} = require('uuid');
const path = require('path');
const fs = require('fs');
const secretFilePath = path.join((process.env.SECRET_DIRNAME ? process.env.SECRET_DIRNAME : __dirname), 'secret.txt');
try {
module.exports = fs.readFileSync(secretFilePath).toString();
} catch (_) {
const secret = uuid();
fs.writeFileSync(secretFilePath, secret);
module.exports = secret;
}