title: adding an environment variable for NodeJS in a javascript file
body: <p>I'm doing some testing on my Vue js application with Nightwatch. Since I have integrated the testing in my gitlab ci/cd I need two different Nightwatch configuration.</p>
  
  <p>In order to achieve that I did the following:</p>
  
  <p>creating two different scripts for local and gitlab test</p>
  
  <pre><code>   "scripts" : {
      "e2e" :  "node test/e2e/gitlab_runner.js" ,
      "local-test" :  "node test/e2e/local_runner.js" ,
      "test": "npm run e2e"
  </code></pre>
  
  <p>Then I embed the variable I need in the <code>local_runner</code> and <code>gilab_runner</code> files</p>
  
  <pre><code>process.env.NIGHTWATCH_CONFIG = 'nightwatch.local.js';
  require('./runner.js');
  </code></pre>
  
  <p>and for the <code>gitlab_runner</code></p>
  
  <pre><code>process.env.NIGHTWATCH_CONFIG = 'nightwatch.conf.js';
  require('./runner.js');
  </code></pre>
  
  <p>then in the file <code>runner.js</code> I have the following line of code</p>
  
  <pre><code>  opts = opts.concat(['--config', 'test/e2e/' + NIGHTWATCH_CONFIG]);
  </code></pre>
  
  <p>So I can get the correct file.</p>
  
  <p>The problem is that when I run the script I get the following error:</p>
  
  <pre><code>(node:21061) UnhandledPromiseRejectionWarning: ReferenceError: NIGHTWATCH_CONFIG is not defined
      at devConfigPromise.then.then (xxxxxx/test/e2e/runner.js:30:51)
      at &lt;anonymous&gt;
      at process._tickCallback (internal/process/next_tick.js:182:7)
      at Function.Module.runMain (internal/modules/cjs/loader.js:697:11)
      at startup (internal/bootstrap/node.js:201:19)
      at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)
  (node:21061) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
  (node:21061) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
  </code></pre>
  
  <p>I have also tried to do the following in the <code>local_runner</code> and <code>gitlab_runner</code> files:</p>
  
  <pre><code>  module.exports = {
      NIGHTWATCH_CONFIG = 'nightwatch.local.js';
    };
  </code></pre>
  
  <p>But then the <code>NIGHTWATCH_CONFIG</code> variable in the <code>runner.js</code> file is undefined.</p>
  
  <p>How can I solve this?</p>