NODE_ENV=production with a differently named conf file

Ghost is version 3.14.0.

I would like to use a file named something other than config.production.json but I would like Ghost to run in production mode. The background is that I wish to launch many copies of Ghost on different ports. So, like,

mktemp current/core/server/config/env/config.XXXXXX.json
cp current/core/server/config/env/config.production.json current/core/server/config/env/config.XXXXXX.json

edit the port number and then

NODE_ENV=XXXXXX node current/index.js

I noticed that, if NODE_ENV=<something_other_than_production> the server performs much more poorly than when NODE_ENV=production, even though the config file current/core/server/config/env/config.XXXXXX.json has the exact same content (save, maybe for the port) than current/core/server/config/env/config.production.json

Would it be possible to add a key to the configuration file, like, maybe { “server”: { “mode”: “production” } } so the server goes into production mode even though the NODE_ENV is set to XXXXXX?

This is the deep, dastardly, dramatic, and disturbing hack that will do what I want:

// hack.js:
// Hacks `fs.readFileSync()`. If the file requested is config.production.json
// and the environment variable NODE_REAL_ENV is set, then it replaces
// "production" in config.production.json with the value of the env var.

const fs = require('fs');
const path = require('path');
fs.readFileSync = (function(orig) {
  return function() {
    const dirname = path.dirname(arguments[0]);
    let filename = path.basename(arguments[0]);
    if (filename === 'config.production.json' && process.env.NODE_REAL_ENV) {
      console.log('Performed hack');
      filename = 'config.' + process.env.NODE_REAL_ENV + '.json';
    }
    arguments[0] = path.join(dirname, filename);
    return orig.apply(this, arguments);
  };
})(fs.readFileSync);

and then

NODE_ENV=production NODE_REAL_ENV=xyzzy node -r hack.js current/index.js

I sincerely hope there is a better way.

Did I mention “dark”? :slightly_smiling_face:

“devious”?