// Dank welcome const fs = require('fs'); const homedir = require('os').homedir(); const config_path = homedir + '/.config/freechat-client/config.json'; function create_config() { let default_config = JSON.stringify({ 'username':null }); fs.writeFile(config_path, default_config, function(err) { if(err) { console.log('Unable to create config\nERR: ' + err); } else { console.log('config created'); return default_config; } }); } function welcome_msg(username) { console.log('welcome message'); let d = document.getElementById('welcome'); d.text('Welcome ' + username); } function get_config() { try { let raw = fs.readFileSync(config_path); return JSON.parse(raw); } catch { return false; } } let config = get_config(); if(!config) { config = create_config(); } if(config['username'] === null){ console.log('no user name setup yet'); } else { welcome_msg(config['username']); }