Using node/express/jade, how to serve one of two javascript files, based on whether or not the first exists?

New to web app development. My problem: I've set grunt up to minify/uglify javascript. That's great and all, but I'd like the server to: see if the minified javascript exists. If it does, serve it. If not, serve the source javascript.

I have a working implementation right now that, inside the routing, checks if the minified file exists. If it does, it serves index.jade, which has layout.jade embedded in it. It not, it serves index_fallback.jade, which has layout_fallback.jade embedded in it.

Routing logic:

/* GET home page. */
router.get('/', function(req, res) {
  if(fs.existsSync(path.join(__dirname + '/../public/' + '/dist/javascripts/global.js'))) {
    res.render('index', { title: 'Express' });
  } else {
    console.log('WARNING!!! Did not find minified global.js file. Using full file.');
    console.log('Run `grunt` to construct minified .js files.');
    res.render('index_fallback', { title: 'Express' });
  }
});

Is there a more elegant way to do this? Maintaining twice as many files with only a line of difference each does not seem like a smart way to do this. Can I pass a variable to jade and do conditionals in the jade templates? Should I do any logic in the router at all?

The source is available at here. Thank you so much.

EDIT: Solved elegantly. See routes/index.js and views/layout.jade from this commit.

Instead of checking for its existance every time, I would cache the path to that file. Or the entire contents of the file, unless RAM is really at a premium. Then just watch for changes on the directory where you expect the preferred file to show up.

var fileName = "lessPreferredFile.js"

router.get('/file', function (req, res) {
    doStuffBasedOn(fileName);
}

fs.watch("directory/of/preferredFile", function (evt, name) {

    //If our file gets added, change the fileName to the updated file name
    //May also want to check the evt parameter for the correct event type.  
    //Wouldn't want to change fileName to the name of a file that just got deleted!
    if (name === "desiredFileName") fileName = name;
}

Note: I didnt test this, consider it javascript pseudo code, but it's pretty close. Also, there are utilities which will recursively watch directories and such, if you can't count on the file you are looking for being placed in a specific directory.