const fs = require('fs')
const images="images"
const path ='images\palmtunnel.jpg'
if(fs.existsSync(path)){
console.log('exist')
}
else{
console.log('does not exist')
}
this way didn't work just working in the files in the same directory.
CodePudding user response:
Have you tried using '/' intead of '\' ?
So your path will be:
const path = 'images/palmtunnel.jpg'
The backslash (\) is an escape character in Javascript (along with a lot of other C-like languages). This means that when Javascript encounters a backslash, it tries to escape the following character. For instance, \n is a newline character (rather than a backslash followed by the letter n). -Daniel JavaScript backslash (\) in variables is causing an error