How to check whether the file exists or not using Node Js Code | Java Inspires

Опубликовано: 04 Октябрь 2024
на канале: Java Inspires
761
2

#JavaInspires
#NodeJsPractice
In Node.js,

From fs module,

fs.access can be used to check whether the file exits in the directory or not

'fs.access(path, [mode],callback);'
where
path = filepath
mode = specifies the accessibilty check
callback = callback function (with err argument)

To check if the file exist or not pass mode as
'fs.constants.F_OK'