title: Nodejs npm step downloads packages on every build in TeamCity
body: <p>I'm a bit of a n00b when it comes to nodejs npm, but since implementing it in our build environment using steps recommended on several articles its tripled our build times.</p>
  
  <p>We use it for the standard stuff (minify/concat/etc js/css/etc)</p>
  
  <p>We use TeamCity and have added a Node.js NPM step then a gulp step to run the tasks (RE: <a href="https://github.com/jonnyzzz/TeamCity.Node" rel="noreferrer">https://github.com/jonnyzzz/TeamCity.Node</a>)</p>
  
  <p>The task to setup NPM takes the most time, 2min 10 seconds, which is over 65% of the total build time calling the command "npm install", which appears to re-download all the packages on each build</p>
  
  <blockquote>
    <p>Step 3/7: NPM Setup (Node.js NPM) (2m:10s)</p>
    
    <blockquote>
      <p>[npm install] Starting: cmd /c npm install</p>
    </blockquote>
  </blockquote>
  
  <p>Out total build times before were around 1min 30sec, including unit tests.</p>
  
  <p>is there anyway to cache these locally and prevent re-download on each build? in the user profile or something maybe as opposed to the build folder?</p>
  
  <p><strong>More detail..</strong></p>
  
  <p>This probably best explains the setup <a href="http://www.dotnetcurry.com/visualstudio/1096/using-grunt-gulp-bower-visual-studio-2013-2015" rel="noreferrer">http://www.dotnetcurry.com/visualstudio/1096/using-grunt-gulp-bower-visual-studio-2013-2015</a></p>
  
  <p>We have C# projects that are using the new Task Runner Explorer, Dependencies are saved into a package.json by this, you pre-run "npm install" once on your local environment in you workspace (need to use a .tfignore to prevent it from checking in to source) then not again, unless you start a new local workspace.</p>
  
  <p>When the build run it needs to run "npm install" from the command line and it picks up dependencies from the package.json file and installs them into a sub folder inside the working directory of the build every time, even if the files are already there from a previous build(i.e. TC agent hasn't cleaned them up), afaik you cant install them outside the working folder. </p>
  
  <p>I could be wrong... Or I should say I hope I'm wrong, and looking for a way for gulp to support this, but what ever way we make it work will need to work with task runner explorer so the F5 experience for the dev is still the same on their local.</p>
  
  <p>We do have multiple agents yes.</p>