Skip to content

Instantly share code, notes, and snippets.

@Tolsee
Created August 9, 2018 04:32
Show Gist options
  • Save Tolsee/4056b6929ea7bd621c89fbb2004c50a5 to your computer and use it in GitHub Desktop.
Save Tolsee/4056b6929ea7bd621c89fbb2004c50a5 to your computer and use it in GitHub Desktop.
Read, write operation in json file.
const fs = require('fs');
const path = require('path');
const readConfig = () => {
const rawConfig = fs.readFileSync(path.join(__dirname, 'config.json'), 'utf8');
return JSON.parse(rawConfig);
};
module.exports.readConfig = readConfig;
module.exports.writeConfig = (config) => {
fs.writeFileSync(path.join(__dirname, 'config.json'), JSON.stringify(config), 'utf8');
};
module.exports.checkAuth = () => {
return !!readConfig().access_token;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment