Wednesday 17 October 2018

node.js: fs.existsSync(path): Check for the existence of a file

fs.existsSync(path)
This function returns true if the path exists, else false.

Find the below working application.

HelloWorld.js
var fs = require('fs');

var filePath = 'out.txt';

if(fs.existsSync(filePath)){
 console.log(`File ${filePath} is already exists`);
}else{
 console.log(`File ${filePath} is not exists`);
}



Previous                                                 Next                                                 Home

No comments:

Post a Comment