Skip to content
This repository was archived by the owner on Jan 5, 2021. It is now read-only.
Alex Lu edited this page Jun 21, 2015 · 4 revisions

Content

  1. Sharing node_modules
## Sharing node_modules Depending on your machine's configuration, you may experience slow `npm install` times.

The speed of scaffolding the project is significantly different when the second question is set to Yes compared to when it is set to No.

? Developing on Windows 10? Yes
? Automatically install dependencies? Yes

vs.

? Developing on Windows 10? Yes
? Automatically install dependencies? No

If you you move the node_modules folder from a project where you've already installed the dependencies in up a directory, every single other project in the same folder will be able to access the dependencies.

This works because of how NodeJS works—not only does it automatically look for node_modules in the current directory, but it checks all the parent directories too.

So if you originally had a folder structure like this:

└── Project1/
    ├── README.md
    ├── gulpfile.js/
    ├── node_modules/    <-- Move this folder up a directory.
    ├── package.json
    └── src/

Just move the node_modules folder up a directory, so the structure now looks like this:

├── Project1/
│   ├── README.md
│   ├── gulpfile.js/
│   ├── package.json
│   └── src/
└── node_modules/       <-- No longer under Project1 directory.

You can now scaffold out as many projects as you like almost instantly because their dependencies are already accessible to them (just make sure you answer No to the Automatically install dependencies? prompt:

├── Project1
│   ├── README.md
│   ├── gulpfile.js/
│   ├── package.json
│   └── src/
├── Project2
│   ├── README.md
│   ├── gulpfile.js/
│   ├── package.json
│   └── src/
├── Project3
│   ├── README.md
│   ├── gulpfile.js/
│   ├── package.json
│   └── src/
└── node_modules/        <-- Shared between Project1, Project2, and Project3.
Clone this wiki locally