Reduce the path length of a Node.js project

If you are using Microsoft Visual Studio to development, I bet you do. If you don't, you will (this isn't any curse that I'm throwing at you)!

Windows has the "Maximum Path Length Limitation" that is terrible for Node.JS projects.

"The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters."

As you know, when you install a package in Node.js, the npm will place the dependencies under the package folder. This process is recursive for each package, so you can easily overcome the path length.

Unfortunately, there's no silver bullet to fix it (I'm not a Node.js guru, so please let me know if I'm wrong), but we can follow some tips to deal with it.

2. Find the packages that are leading you into the limit and install them

Imagine that you install a package that has a dependency from request and that dependency made you overcome the path limit.
Go to the npm and install the package explicitly. Now, Node.js will not install the request in a subfolder of your first package.

npm install request --save

3. Remove dev packages

Install the packages with the "--production" flag to remove all development only packages.

npm install --production

4. Remove duplicated packages

Npm has a command that will find for you the duplicated dependencies and install them as top dependencies.
With a simple command you can simplify your dependency tree and reduce your project size.