2022-11-27 02:35:28 -05:00
|
|
|
const fs = require('fs/promises')
|
2022-08-14 05:51:45 -04:00
|
|
|
|
2022-11-15 21:33:16 -05:00
|
|
|
/**
|
|
|
|
* check if file exists
|
|
|
|
* @param {String} filepath the file path
|
|
|
|
* @return {boolean} if file exists true else false
|
|
|
|
*/
|
2022-11-27 02:35:28 -05:00
|
|
|
async function fileExists (filepath) {
|
2022-08-14 05:51:45 -04:00
|
|
|
try {
|
2022-11-27 02:35:28 -05:00
|
|
|
await fs.access(filepath)
|
|
|
|
return true
|
2022-08-14 05:51:45 -04:00
|
|
|
} catch (error) {
|
2022-11-27 02:35:28 -05:00
|
|
|
if (error.code !== 'ENOENT') throw error
|
2022-08-14 05:51:45 -04:00
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
return false
|
2022-08-14 05:51:45 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
module.exports = fileExists
|