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