const fs = require('fs')

function fileExist(filename = '') {
  try {
    fs.accessSync(filename)
  } catch (e) {
    return false
  }

  return true
}

function writeFile(filename, data) {
  return new Promise((resolve, reject) => {
    fs.writeFile(filename, data, error => {
      if (error) { reject(error); return }

      resolve()
    })
  })
}

function readFile(filename) {
  return new Promise((resolve, reject) => {
    fs.readFile(filename, (error, data) => {
      if (error) { reject(error); return }

      resolve(data)
    })
  })
}

module.exports = exports = {
  fileExist,
  writeFile,
  readFile
}

const fs = require('fs')

function fileExist(filename = '') {
  try {
    fs.accessSync(filename)
  } catch (e) {
    return false
  }

  return true
}

function writeFile(filename, data) {
  return new Promise((resolve, reject) => {
    fs.writeFile(filename, data, error => {
      if (error) { reject(error); return }

      resolve()
    })
  })
}

function readFile(filename) {
  return new Promise((resolve, reject) => {
    fs.readFile(filename, (error, data) => {
      if (error) { reject(error); return }

      resolve(data)
    })
  })
}

function chmod(filename, rights) {
  return new Promise((resolve, reject) => {
    fs.chmod(filename, rights, error => {
      if (error) { reject(error); return }

      resolve()
    })
  })
}

module.exports = exports = {
  fileExist,
  writeFile,
  readFile,
  chmod
}

Add method to promisify chmod function
Add method to promisify chmod function
