kafka-dance-api/config.js

29 lines
645 B
JavaScript
Raw Permalink Normal View History

const fs = require('fs')
const path = require('path')
const homedir = require('os').homedir()
const configFilePath = homedir + path.sep + '.kafka-dance.json'
const emptyConfig = () => ({
2022-09-08 21:51:10 -04:00
clusters: {},
frontendUrl: 'http://localhost:5173',
})
const readConfig = () => {
2022-09-08 21:51:10 -04:00
if (fs.existsSync(configFilePath)) {
try {
return JSON.parse(fs.readFileSync(configFilePath).toString())
} catch (e) {
console.error(e.toString())
}
}
2022-09-08 21:51:10 -04:00
return emptyConfig()
}
const storeConfig = async config =>
fs.writeFile(configFilePath, JSON.stringify(config, null, 2), console.error)
module.exports = {
readConfig,
storeConfig
}