title: How do I get a list of files with specific file extension using node.js?
body: <p>The node <a href="https://www.npmjs.com/package/node-fs" rel="noreferrer">fs</a> package has the following methods to list a directory:</p>
  
  <blockquote>
    <p><strong>fs.readdir(path, [callback])</strong> Asynchronous readdir(3). Reads the
    contents of a directory. The callback gets two arguments (err, files)
    where files is an array of the names of the files in the directory
    excluding '.' and '..'.</p>
    
    <p><strong>fs.readdirSync(path)</strong> Synchronous readdir(3). Returns an array of
    filenames excluding '.' and '..</p>
  </blockquote>
  
  <p>But how do I get a list of files matching a file specification, for example <strong>*.txt</strong>?</p>