title: Evalute JS file with template strings from another file
body: <p>I would like to make use of a function called <a href="https://electron.atom.io/docs/api/web-contents/#contentsexecutejavascriptcode-usergesture-callback" rel="nofollow noreferrer">executeJavaScript()</a> from the Electron webContents API. Since it is very close to eval() I will use this in the example.</p>
  
  <h2>The problem:</h2>
  
  <ul>
  <li>I have a decent sized script but it is contained in a template string.</li>
  <li>Expanding this app, the script could grow a lot as a string.</li>
  <li>I am not sure what the best practices are for this.</li>
  </ul>
  
  <p><strong><em>I also understand that <code>eval()</code> is dangerous, but I am interested in the principal of my question.</em></strong></p>
  
  <h2>Basic eval example for my question:</h2>
  
  <pre><code>// Modules
  const fs = require('fs');
  
  // CONSTANTS
  const EXAMPLE_1 = 'EXAMPLE_1';
  const EXAMPLE_2 = 'EXAMPLE_2';
  const EXAMPLE_3 = 'EXAMPLE_3';
  
  const exampleScriptFunction = require('./exampleScriptFunction');
  const exampleScriptFile = fs.readFileSync('./exampleScriptFile.js');
  
  // using direct template string
  eval(`console.log(${EXAMPLE_1})`);
  
  // using a method from but this doesnt solve the neatness issue.
  eval(exampleScriptFunction(EXAMPLE_2));
  
  // What I want is to just use a JS file because it is neater.
  eval(`${exampleScriptFile}`);
  </code></pre>
  
  <h3>exampleScriptFunction.js</h3>
  
  <pre><code>module.exports = function(fetchType) {
    return `console.log(${fetchType});`;
  }
  </code></pre>
  
  <ul>
  <li>This will allow me to separate the script to a new file</li>
  <li>what if I have many more then 1 variable???</li>
  </ul>
  
  <h3>exampleScriptFile.js:</h3>
  
  <pre><code>console.log(${EXAMPLE_3});
  </code></pre>
  
  <ul>
  <li>This clearly does not work, but I am just trying to show my thinking.</li>
  <li>back ticks are not present, fs loads as string, main file has back ticks. </li>
  <li>This does not work. I do not know how else to show what I mean.</li>
  <li>Because I am loading this will readFileSync, I figured the es6 template string would work.</li>
  <li>This allows me to write a plain js file with proper syntax highlighting</li>
  <li>The issue is the variables are on the page running the eval().</li>
  </ul>
  
  <p>Perhaps I am completely wrong here and looking at this the wrong way. I am open to suggestions. Please do not mark me minus 1 because of my infancy in programming. I really do not know how else to ask this question. Thank you.</p>