// node modules
import fs from 'fs';
// npm modules
import homedir from 'homedir';
// homedir() is a cross platform way of getting the users home directory.
// On macOS it would end up being '/Users/username/.urcli_config.json'.
const configFilePath = `${homedir()}/.urcli_config.json`;

class Config {
  constructor() {
    try {
      const config = JSON.parse(fs.readFileSync(configFilePath));
      Object.assign(this, config);
    } catch (e) {
      // We can ignore ENOENT and throw on everything else.
      if (e.code !== 'ENOENT') {
        console.error('Error reading from filesystem.');
        throw new Error(e);
      }
    }
  }
  save(configValues) {
    Object.assign(this, configValues);
    const config = JSON.stringify(this, null, 2);
    try {
      fs.writeFileSync(configFilePath, config);
    } catch (e) {
      console.error('Unable to save the config file.');
      throw new Error(e);
    }
    console.log('configuration saved:');
    console.log(config);
    return Promise.resolve();
  }
}

export const config = new Config();

@@ -80,153 +80,8 @@
 r';%0A
-// homedir() is a cross platform way of getting the users home directory.%0A// On macOS it would end up being '/Users/username/.urcli_config.json'.
 %0Acon
@@ -778,98 +778,19 @@
     
-console.log('configuration saved:');%0A    console.log(config);%0A    return Promise.resolve()
+return this
 ;%0A  

Return the config object instead of a promise