I'm currently converting some code from Node JavaScript into TypeScript
I have a file called keys.js
let keys;
try {
// eslint-disable-next-line security/detect-non-literal-fs-filename
keys = JSON.parse(fs.readFileSync(credsPath, 'utf8'));
} catch (error) {
return logger.error('initKeysParseError', error, { credsPath });
}
if (keys) {
logger.info('initKeysSuccess', 'keys ready', null);
return (module.exports.keys = keys);
}
return logger.error('initKeysError', null, { credsPath });
And when I wanted to use keys in another file, I would
const { keys } = require('./keys');
console.log(keys.account.username);
I'm having some issue doing this in typescript
How can I initialize the keys variable only once and then be able to do
import keys from './keys';
?
Thanks!