Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Last active April 13, 2017 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelmota/a3b1153c3afc9dfb73a4762264f8d4d3 to your computer and use it in GitHub Desktop.
Save miguelmota/a3b1153c3afc9dfb73a4762264f8d4d3 to your computer and use it in GitHub Desktop.
Node.js check if exact filename exists
var fs = require('fs');
var path = __dirname;
var filename = 'test.txt';
var files = fs.readdirSync(path);
var exists = files.includes(filename);
// true if file on disk is "test.txt",
// false if file on disk is "TEST.txt"
// fs.existsSync() will return true hence not using
console.log(exists);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment