Here's an idea you might want to refine:
var ejs = require('ejs');
//Express.js setup
...
app.use('/public/js/myfile.js', function(req, res){
var f = ejs.compile('var host = <%= hostname %>;');
var fileContent = f({hostname: 'somevalue'});
res.setHeader('Content-Type', 'application/javascript');
res.setHeader('Content-Length', fileContent.length);
res.send(fileContent);
});
app.use(express.static(path.join(__dirname, 'public')));
//Routes definition
...
I used ejs since that's what you already use. So the idea is to have a middleware that catches requests to those "dynamic" javascript files, and use the template engine to compile the content.
Note that I use a simple string variable here, but you could read the file from disk and then compile it.
Cheers