K
K
kuzubina2020-06-06 14:30:11
JavaScript
kuzubina, 2020-06-06 14:30:11

How to check if a file exists on the server by making a get request to the express.js server?

It is necessary to check the existence of a file on the server by sending a request from the frontend, how and what is the best way to implement this?
I try like this

if (fs.existsSync('product.js')) {
  console.log('OK')
} else {
  console.log('Not found')
}

I just run it in the file - it works, if I put this code in the express router, it doesn't work

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Solomonov, 2020-06-06
@Wendor

Check file with full path

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question