How to use a .gitignore File In NodeJS
The .gitignore file tells Git which files or directories to ignore. Adding node_modules to this file ensures that the folder is not tracked by Git.
Syntax
node_modules/
Example: We will create a .gitignore file in the root of our project and add the node_modules entry to it.
Step 1: Create a .gitignore File
In the root of your project directory, create a file named .gitignore.
Step 2: Add node_modules Entry
Open the .gitignore file in a text editor and add the following line:
node_modules/
Step 3: Save and Close the File
Save the .gitignore file and close the text editor.
How to Ignore ‘node_modules’ Folder in Git?
The node_modules
folder is a directory where npm (Node Package Manager) installs all the dependencies for a Node.js project. Including this folder in your Git repository is unnecessary and can significantly bloat your repository size. Instead, you should ignore it using Git’s .gitignore
file. This article will guide you through the steps to properly ignore the node_modules
folder in your Git repository.