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!
Getting Started with Solid
How to deploy a .NET app using Docker
Best Visual Studio Code Extensions for 2022
How to build a Discord bot using TypeScript
How to deploy a Deno app using Docker
Getting Started with Deno
How to Scrape the Web using Node.js and Puppeteer
Getting Started with React
Setting Up Stylus CSS Preprocessor
Getting Started with Vuex: Managing State in Vue
Setting Up a Local Web Server using Node.js
How To Create a Modal Popup Box with CSS and JavaScript
