Table of Contents
When you work in Node, you often will have a node_modules folder. This is because this is the folder where all the modules you have installed are stored.
This folder is not needed in your Git repository because it is not part of the source code and can be fairly large.
So, rather than having a node_modules folder in your Git repository, you should instead commit your package.json and package-lock.json files so that the user who clones your project can install the modules they need themselves.
In this post, we'll learn how we can exclude the node_modules folder from Git so that it is not included in the repository.
Excluding the node_modules folder from Git
The best way to exclude a folder from Git is to add a .gitignore file to the root of the project.
This file will contain a list of files and folders that you want to exclude from Git.
Inside the .gitignore file, you should add this line:
BASHnode_modules
This will tell Git not to track the node_modules folder, and therefore, ignore it when you commit your changes.
Remove Tracked node_modules Folder
If you've already committed your node_modules folder, you will need to tell Git to untrack it.
To do this, run this command:
BASHgit rm -r --cached node_modules
From here, Git will remove the node_modules folder from your Git repository. Now commit your changes.
BASHgit commit -m "Remove node_modules"
Then push your changes to the remote repository.
BASHgit push
That's it! Now, when you clone your project, the node_modules folder will not be included in the repository.
Conclusion
In this post, we've learned how to ignore the node_modules folder from Git. We also learned how to untrack it if you've already committed it.
Hopefully, this has been helpful and thanks for reading!
How to Install Node on Windows, macOS and Linux
Managing PHP Dependencies with Composer
Getting Started with Svelte
Getting Started with Express
Create an RSS Reader in Node
How to deploy a .NET app using Docker
Best Visual Studio Code Extensions for 2022
Getting Started with Deno
Getting Started with Sass
Learn how to use v-model with a custom Vue component
Getting User Location using JavaScript's Geolocation API
Getting Started with Vuex: Managing State in Vue
