title: Is there any benefit installing d3.js via npm for Angular 2 TypeScript project?
body: <p><strong>TL;DR:</strong> d3.js should be installed via npm, as should the typings. Accepted answer has details. I was new to Angular when I wrote this question. The <code>npm</code> process is the standard: for tree-shaking, package management, updating etc</p>
  
  <hr>
  
  <p>I have an Angular 2 project (it's the Quick Start project for simplicity), and I'm importing d3.js version 4. There is no TypeScript definitions with d3, as it's javascript only. </p>
  
  <p>In the index.html I add the lib:</p>
  
  <pre><code>&lt;script src="https://d3js.org/d3.v4.min.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>In the typescript app.component.ts, I reference the d3.select().... and it works fine - draws a circle: </p>
  
  <pre><code>d3.select("body").append("svg").attr("width", 50).attr("height", 50).append("circle").attr("cx", 25).attr("cy", 25).attr("r", 25).style("fill", "purple");
  </code></pre>
  
  <p>Visual Studio Code does not recognise d3 so I install the typings from DefinitelyTyped - the IDE then recognises d3, and I get code completion etc:</p>
  
  <pre><code>typings install dt~d3 --save --global
  </code></pre>
  
  <p>Now, I tried a second project, but went the <code>npm</code> route, <code>npm install --save d3</code> and I can reference the d3.js via the <em>node_modules</em> in index.html using </p>
  
  <pre><code>&lt;script src="node_modules/d3/build/d3.min.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>But, I do not see why I would use npm in this instance? I'm not using import statements for d3 in the component.ts files, and it works ok anyway. Maybe I'm missing something here? </p>