Node.js Check if a File Exists Reference

In NodeJS, to check if a file exists, you can use a quick and simple method in the “fs”┬ámodule.

How to Check if a File Exists in Node.js

//load the fs module
var fs = require('fs');

fs.exists('/path/file.txt', function (exists) {
  if(exists) {
    console.log("file exists");
  } else {
    console.log("file not found");
  }
});