Substitute data in createReadStream in Node.js

I'm not really sure I'm asking the right question here... so please don't attack me.

I'm creating my own asynchronous callback library for a type of tracking implementation. The user must install a piece of code on their site that contains a unique account number. Think Google Analytics.

The library call reaches out to my node server and passes along the account id in the query parameter.

Node responds with the analytics library so various tracking functions can be called on the user's site.

My question is, how can I modify my static tracking library that gets streamed back to the user's page based on the query parameter? For instance, once the account ID is read off the query string, I do a DB look-up to find some values in the library that are specific to that user and would like to modify particular functions in my library appropriately.

I'm reading a static file off my local server with: fs.createReadStream("./file.js");

How can I modify that file to substitute certain values within for others?

Or should I be reading the file in to an in-memory object at startup and then simply writing out modified data via the response object?

You could simply use eco or ejs templates for this, but for just to have an idea or if you prefer to make this yourself, I think you should make a template based on your file.js and then write user specific parts of the code with the corersponding data using a set of regular expressions.

For example:

template.js

var get_user = function () {
  return "Hi %%USER_NAME%%"
}

then req.send()` the content of template.js replaced something like this:

var result = cached_template_data;
if (!result) {
  fs.readFile("./template.js", function (err, data) {
    result = cached_template_data = data;
    if (!err) {
      result = result.replace(/%%USER_NAME%%/g, user.name)
      res.send(result);
    } else {
      // Big oops
      res.send({error:true}, 500);
    }
  })
} else {
  result = result.replace(/%%USER_NAME%%/g, user.name)
  res.send(result);
}

UPDATE

Consider caching whenever possible by the way...