title: How do I save an svg node to a file using nodejs?
body: <p>I'm using d3 through a small helper package: <a href="https://www.npmjs.com/package/d3-node" rel="nofollow noreferrer">https://www.npmjs.com/package/d3-node</a></p>
  
  <p>I created my svg file using d3-node, here's the code.</p>
  
  <pre><code>const D3Node = require('d3-node')
  
  var d3n = new D3Node()
  var svg = d3n.createSVG()
      .style("width","1920px")
      .style("height","1080px") 
      .attr("preserveAspectRatio","true")
  .html(firstTemplate)
  .append("myCustomTag")
  </code></pre>
  
  <p>Now after this, I have no idea how to save the output. The main problem is in <code>myCustomTag</code>.</p>
  
  <pre><code>console.log(d3n.d3Element.select("svg").node().innerHTML)
  </code></pre>
  
  <p>This line is supposed to output my svg, and it does, except that <code>myCustomTag</code> becomes <code>mycustomtag</code>and my svg gets corrupt.</p>
  
  <p>I have tried <code>select("svg").node().outerHTML</code>, <code>select("svg").html()</code>, innerText, I just couldn't find anything.</p>
  
  <p>I can't use the innerHTML in this case, is there a way to store the svg file directly from the d3 variable?  </p>