const fs = require('fs').promises;
const constants = require('fs').constants;
fs.access('./folder', constants.F_OK | constants.W_OK | constants.R_OK)
.then(() => {
return Promise.reject('folder is already exists');
})
.catch((err) => {
if (err.code === 'ENOENT') {
console.log('no folder so mkdir folder');
return fs.mkdir('./folder');
}
return Promise.reject(err);
})
.then(() => {
console.log('success');
return fs.open('./folder/file.js', 'w');
})
.then((fd) => {
console.log('success make empty file', fd);
return fs.rename('./folder/file.js', './folder/newFile.js');
})
.then(() => {
console.log('success name change');
})
.catch((err) => {
console.error(err);
});