Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Stheven Cabral
.a{fill-rule:evenodd;}techdegree seal-36
Stheven Cabral
Full Stack JavaScript Techdegree Graduate 29,840 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
12,972 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.