Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript npm Basics (retiring) Installing Packages with npm Managing Dependencies in the package.json File

Stheven Cabral
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Stheven Cabral
Full Stack JavaScript Techdegree Graduate 29,854 Points

Help understanding gitignore

Say you use gitignore to ignore the node_modules folder, and you commit your project folder containing the node_modules folder to a repository. If another user clones your repository, will the node_modules folder not exist in the cloned repository? Will the user have to install all dependencies on there own?

Blake Larson
Blake Larson
13,014 Points

Yeah they can just run npm install and it will automatically download the dependencies listed in the package.json.

1 Answer

Each file in your working directory can be in one of two states: tracked or untracked. Tracked files are files that Git knows about, and untracked files are everything else.

gitignore file specifies untracked files that Git should ignore, so tracked files are not affected. So it depends on the state of your node_modules folder.

The image below shows the lifecycle of the state of your files: alt text

In the image above all files that are unmodified or modified are tracked files.

To find out the state of your files you can run the following command

git status

This will show which files are in which state in your project.

If node_modules aren't in the cloned repository, the user that cloned it can run

npm install

like Blake Larson said in the comment above. The npm install command checks a file called package.json for all the dependencies that the project are dependent on, and install them for the user.