How to check if a file exists in the 's3' / 'azure' path using node js. fs.stat()
or fs.existsSync(path)
returns false even if the file exists in the path.
Asked
Active
Viewed 285 times
1
-
1Possible duplicate of [How to determine if object exists AWS S3 Node.JS sdk](https://stackoverflow.com/questions/26726862/how-to-determine-if-object-exists-aws-s3-node-js-sdk) – Artem Arkhipov Sep 05 '18 at 10:52
-
The solution is, where '**request**' is [link](https://www.npmjs.com/package/request), const req = require('request'); req .get('azure_image_path') .on('response', function (res) { if (res.statusCode === 200) { //On Sucsess do something } else { //On Error, handle the error } })` With all other methods it fails, with this method the success and failures results are returned. This worked for me. – Revathi P Sep 07 '18 at 07:24
1 Answers
1
Import https://www.npmjs.com/package/@types/request
const request = require('request');
request
.get(cdn_image_path)
.on('response', function (res) {
if (res.statusCode === 200) {
//Do something
} else {
//Do something if file is absent
}

Revathi P
- 51
- 8