Node: Search for a filetype in a folder

I wonder what's the best way to search for template files that has the format *.tmpl.* like comment.tmpl.dotin Node and take the content of the file and execute it as a parameter in a callback?

My basic plan would be

  1. Read the directory
  2. Use a regex to match your filename pattern
  3. Read the file and do whatever you need to it

Here is some code to get you started, and here is the filesystem API in NodeJs http://nodejs.org/api/fs.html

    var fs = require('fs'),
    sourcePath = '/your path/'; 

    var files = fs.readdirSync(sourcePath);

    for (var f in files){
        var file = files[f];

        if (file.match(/.*\.tmpl\..*/) {

            // do whatever you want e.g. read the file
            fs.readFile(file, function (err, data) {
                 if (err) throw err;
                 console.log(data);
            });
        }
    }