title: Node.js : how to pass JS variable's value from script to terminal?
body: <p>Given a JS script running <a href="http://bl.ocks.org/hugolpz/f02abc3d4a395f280f6a" rel="nofollow noreferrer">a D3js dynamic dataviz</a></p>
  
  <p><img src="https://i.stack.imgur.com/bVH9G.png" alt="enter image description here"></p>
  
  <p>I currently print out a single view into a <code>output.svg</code> file using :</p>
  
  <p><strong><a href="https://github.com/hugolpz/svgcreator.node.js" rel="nofollow noreferrer"><code>svgcreator.node.js</code></a> :</strong></p>
  
  <pre><code>var jsdom = require('jsdom');
  jsdom.env(
    "&lt;html&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;",        // CREATE DOM HOOK:
    [ 'http://d3js.org/d3.v3.min.js',    // JS DEPENDENCIES online ...
    'js/d3.v3.min.js' ],                 // ... &amp; offline
  // D3JS MAP DRAWING CODE * * * * * * * * * * * * * * * * * * * 
    function (err, window) {
  
      var svg = window.d3.select("body")
          .append("svg")                 // append svg on body
         ...                             // more D3js code
      // END svg design
  
    //PRINTING OUT SELECTION
      console.log(window.d3.select("body").html());
   }
  // END (D3JS) * * * * * * * * * * * * * * * * * * * * * * * *
  );
  </code></pre>
  
  <p><strong>Terminal NodeJS command :</strong></p>
  
  <pre><code>node svgcreator.node.js &gt; output.svg
  </code></pre>
  
  <p>The way it works is that each <code>console.log()</code> message from <code>svgcreator.node.js</code> script is printed into the file <code>output.svg</code> file.</p>
  
  <p>Since this D3js dataviz turn around the globe, It should be possible to print out one <code>console.log()</code> message for each view into a proper svg file named correctly. I thing I should get a variable such <code>var country=...;</code> from the JS script <strong>up to the terminal</strong>. Then, I could do <strong>(?)</strong> something such :</p>
  
  <pre><code>node svgcreator.node.js &gt; $(JsVar.country).svg    # nb: this var syntax if fictional 
  </code></pre>
  
  <p>So whenever a console.log() message come, the message in printed into an SVG file with the correct name.</p>
  
  <p>Also, <strong>how to pass JS variable's value from script to terminal ?</strong></p>
  
  <p>See also: <a href="https://stackoverflow.com/questions/25220267/">Node.js : how to pass parameter&#39;s value from terminal to JS script</a></p>