Best way of packaging node_modules


We have an octopus project to deploy a windows service that also hosts a single page web app through nancy. We’ve found that packaging up the node_modules directory inside the nuget package causes the build to take huge amounts of time. Apparently this is a problem with nuget packaging lots of files. Given this, are there any recommended ways of deploying a website with a large node_modules folder? We’ve considered running npm again manually on the target hosts but that doesn’t seem like a great way to go.


Hi Tom,

Thanks for getting in touch! The packaging of that directory takes a long time due to the 10’s of thousands of files in that directory, and is limited by how quickly the OS can read them and zip them (as you can see if you try and copy or zip that folder yourself).

Typically you would not deploy the node_modules folder (in the .NET world at least). NPM packages include the source. Only the javascript/css/img files that is directly referenced is required. The rest of the files are there so that you can recompile the library for whatever reason.

The node_modules folder is not usually included in your Visual Studio project file, so it is not automatically picked up by Octopack. The most common approach is to use gulp to bundle the dependencies into one vendor.js file (see the ASP.NET gulp documentation. Alternatively you can specify the files you need explicitly in the nuspec or reference them in your project.

Hope that helps!

Robert W

That’s great thanks Robert