i use this code to specify whether or not a file exists:
if(fs.exists('../../upload/images/book/2.jpg')){
console.log("yes the file exist");
} else{
console.log("there is no file");
}
While the file is there, it always says it does not exist(there is no file)
i use fs.stat(...) too , but again it gives the result (there is no file)
Folder structure:
root_app
--------|.tmp
--------|api
------------|controllers
------------------------|BookContoller.js (My code run from here)
--------|...(And the rest of the folders)
--------|upload
---------------|images
----------------------|book
---------------------------|2.jpg
thank you
fs.existsis asynchronous. To make your code work you could just change it tofs.existsSync.Also you have the wrong path to your file, you need to use
path.resolveor__dirname, so the script will know where to find the file.See documentation: